I tried to evaluate $\frac{1}{2\pi i}\oint_C \frac{z^2}{z^2+4}dz$ where C is the square with vertices $\pm2$, $\pm2+4i$ thusly:
$$\frac{1}{2\pi i}\oint_C \frac{z^2}{z^2+4}dz=\frac{1}{2\pi i}\oint_C \frac{z^2}{(z+2i)(z-2i)}dz$$
So I can take,
$$f(a_1)=\frac{1}{2\pi i}\oint_C \frac{z^2/(z-2i)}{z+2i}dz$$ and $$f(a_2)=\frac{1}{2\pi i}\oint_C \frac{z^2/(z+2i)}{z^2+4}dz$$ according to Cauchy's integral formula. Then my answer is,
$$\frac{(-2i)^2}{-2i-2i}+\frac{(2i)^2}{2i+2i}=\frac{-4}{-4i}+\frac{-4}{4i}=\frac{1}{i}+\frac{-1}{i}=0$$
before realizing that $2i$ is in $C$, but $-2i$ is not. I assume I can't do this, but also can't think of another way to go about the problem.
If a singularity lies outside the curve, then it doesn't contribute to the integral.