9. Solution: If $b1$, the number $a^{b}$ is not an integer.

For $a=1$, we get $1=b+2, b=-1$.
For $a=-1$, we get $(-1)^{b}=-b+2$, this equation has no solution. In fact, when $b>0$, the number $a^{b}$ is divisible by $a$, so $a$ divides 2, because $a^{b}-a b=2$, therefore, $a=-2$, $-1,1,2$.
If $a=-2$, we have $(-2)^{b}=-2 b+2$, i.e., $(-2)^{b-1}=b-1$; it is impossible for any $b \in \mathbf{Z}$ to satisfy this equation.
In fact, if the number $b$ satisfies the equation, it should be odd, i.e., $b=2 s+1$. The equation can be rewritten as $4^{s}=2 s$. This is impossible, because for any real number $s$, $4^{s}>2 s$.
If $a=-1$, then we have $(-1)^{b}=-b+2$, i.e., $|-b+2|=1$.
Therefore, $b=1$ or 3, but only $b=3$ satisfies the equation $(-1)^{b}=-b+2$.
If $a=1$, then we have $1=b+2$, which has no solution under the condition $b>0$.
If $a=2$, then we have $2^{b}=2(b+1)$, i.e., $2^{b-1}=b+1$, which has only one solution $b=3$.
When $b>3$, it is easy to prove by mathematical induction that $2^{b-1}>b+1$.
Therefore, all pairs $(a, b)$ that satisfy the equation are $(2,3),(1,-1),(-1,3)$.
9. (2004 Slovenia Mathematical Olympiad) Find all integer solutions to the equation $a^{b}=a b+2$.

Translate the above text into English, please keep the original text's line breaks and format, and output the translation result directly.