How do I evaluate $\frac{1}{2 \pi i} \oint_{C} \frac{z^{2} d z}{z^{2}+4}$ How do I evaluate the following integral when where $C$ is the square with vertices at $\pm2, \pm2+4i$,
$$\frac{1}{2 \pi i} \oint_{C} \frac{z^{2} d z}{z^{2}+4}$$
Using Cauchy integral:
$\frac{z^{2}}{z^{2}+4}=\frac{z^2}{(z+2i)(z-2i)}=\frac12\frac{z^2}{z+2i}+\frac12\frac{z^2}{z-2i}$ then $\frac{1}{2 \pi i} \oint_{C} \frac{z^{2} d z}{z^{2}+4} \implies \frac{1}{2 \pi i} \oint_{C} \frac12\frac{z^2 d z}{z+2i}+\frac{1}{2 \pi i} \oint_{C} \frac12\frac{z^2 d z}{z-2i}$
$\frac{z^2}{z+2i}$ is analytic on and inside $C$, hence we can apply Cauchy theorem and for the second term we use Cauchy integral formula,
$$\frac{1}{2 \pi i} \oint_{C} \frac12\frac{z^2 d z}{z+2i}+\frac{1}{2 \pi i} \oint_{C} \frac12\frac{z^2 d z}{z-2i}=0+\frac{1}{4\pi i}2\pi i \times f(2i)=-2$$
Using Residue Theorem:
$2i$ is the only isolated singularity in $C$.
$$\frac{1}{2 \pi i} \oint_{C} \frac{z^{2} d z}{z^{2}+4}=\frac{1}{2 \pi i} 2\pi i \times \text{Res}(f,2i)=i$$
I get correct answer for Residue Theorem but couldn't understand where I do wrong when using  Cauchy integral.
It will be great help if someone clear me when to use which method to find the integral.

I will perform the first computation in a slightly different manner:
$$
\begin{aligned}
\frac{1}{2 \pi i} \oint_{C} \frac{z^2 }{z^2+4}\; dz
&=
\frac{1}{2 \pi i} \oint_{C} \frac{(z^2 + 4) - 4}{z^2+4}\; dz
\\
&=
\frac{1}{2 \pi i} \oint_{C} dz
+
\frac{1}{2 \pi i} (-4)\oint_{C} \frac1{z^2+4}\; dz
\\
&=
0
+
\frac{1}{2 \pi i} (-4)\oint_{C} \frac 1{4i}\left(\frac1{z-2i} - \frac1{z+2i}\right)\; dz
\\
&=
\frac{1}{2 \pi i} \cdot i\oint_{C} \frac{dz}{z-2i}
-
\frac{1}{2 \pi i} \cdot i\oint_{C} \frac{dz}{z+2i}
\\
&= i-0\ .
\end{aligned}
$$
