When learning a language, grammar rules are useful because they show you how the language normally behaves. For example, you might learn that the word "to" is followed by the infinitive of the verb. The rule tells you that "to have" is correct and "to having" is wrong.
However, you should also be prepared to meet some exceptions to the grammar rules that you learn. For example, students are often confused by phrases like 'look forward to having' or 'advantages to having', both of which are correct.
When you find an exception to a grammar rule, don't get frustrated; consider it an opportunity to expand your knowledge of the language, and perhaps to impress the examiner!