Contour integral of $\displaystyle\oint_{c} \frac{e^{ix}}{1+z^{2}} dz$ I want to find $\displaystyle\int_{-\infty}^{\infty} \frac{\cos x}{x^{2} + a^{2}}\ dx$
using
$$\oint_{c} \frac{e^{ix}}{1+z^2} \cdot d z$$
over the upper half of a large semicircle enclosing $z=i$  (not $\oint_{c} \frac{e^{iz}}{1+z^{2}} dz$)
For very large semicircle,  the above integral   reduces to $$\oint \frac{e^{i x}}{1+z^{2}} d z=\int_{-\infty}^{\infty} \frac{e^{i x}}{1+x^{2}}dx=\int_{-\infty}^{\infty} \frac{\cos x d x}{1+x^{2}}+i \int_{-\infty}^{\infty} \frac{\sin x}{1+x^{2}} d x$$
So we have $$\oint \frac{e^{i x}}{1+z^{2}} d z=\int_{-\infty}^{\infty} \frac{\cos x}{1+x^{2}} d x+i\int_{-\infty}^{\infty} \frac{\sin x}{1+x^{2}} d x$$
Also by residue theorem $$\oint \frac{e^{i x}}{1+z^{2}} d z=2 \pi i b_{1}$$  and then

$$b_{1}=\lim _{z \rightarrow i} \frac{e^{i x}(z-i)}{1+z^{2}}=\frac{1}{2 i}$$ ( as $z$--> $i$ , the real part $x$--> $0$ )

Therefore we have$$\int_{-\infty}^{\infty} \frac{\cos x}{1+x^{2}} d x+\int_{-\infty}^{\infty} \frac{\sin x}{1+x^{2}} d x=\frac{2 \pi i}{2 i}$$
And hence $$\int_{-\infty}^{\infty} \frac{\cos x}{1+x^{2}} d x=\pi$$  which is incorrect.
Why am I getting wrong result. I suspect the above highlighted portion.
Can anyone please help me. Thank you so much
 A: Your error is that you did not change consequently the real variable $x$ to complex variable $z$. As a consequence your integrated function is wrong as seemingly $x$ is independent of $z$.
As a result you have wrongly computed the residue at $z=i$. The correct value is:
$$
\operatorname{res}(f(z),i)=\lim _{z \rightarrow i} \frac{e^{i \color{red}z}(z-i)}{1+z^{2}}=\frac{e^{-1}}{2 i}.
$$

UPDATE (after OP question was edited clarifying that symbol $x$ used in the integrated function is assumed to mean the real part of $z$)
You cannot integrate the function $$f(z)=\frac{e^{i\operatorname{Re}z}}{1+z^2}$$
with the help of the residue theorem because the function is holomorphic at no point of the complex plane, whereas the residue theorem requires it to be holomorphic at any point of the part of the complex plane surrounded by the contour except for a finite set of isolated points.
To avoid this you shall instead use the meromorphic function
$$
f(z)=\frac{e^{iz}}{1+z^2}
$$
as suggested above.
