# How to use Mathematica to do a complex integrate with poles in real axis?

I want to use Mathematica to compute the following complex integral:

Integrate[Exp[I z ] 1/z, {z, -Infinity, Infinity}]

Mathematica reports that it does not converge on {-Infinity, Infinity}.

But, from the textbook, we know, the result is I Pi.

Of course, if I use NIntegrate, then, Mathematica will give 0. + 3.14 I.

Try

Integrate[Exp[I z] 1/z, {z, -Infinity, Infinity},PrincipalValue -> True]
(*I π*)

One can also consider using the residue theorem. The residue is readily obtained by

Residue[Exp[I z] 1/z, {z, 0}]

returning 1, which means that the integral is $$\mathrm i \pi$$.