Let's have the improper integral
$$ \int_{-\infty}^{+\infty} \frac{2x}{x^2+1} \,\mathrm{d}x = \int_{-\infty}^{0} \frac{2x}{x^2+1} \,\mathrm{d}x + \int_{0}^{+\infty} \frac{2x}{x^2+1} \,\mathrm{d}x. $$
Since
$$ \int_{0}^{+\infty} \frac{2x}{x^2+1} \,\mathrm{d}x = \int_{0}^{+\infty} \frac{1}{u+1} \,\mathrm{d}u = \lim_{b\to\infty} \ln\lvert b+1\rvert - \ln\lvert 0+1 \rvert = \infty, $$
we can say that the integral from $-\infty$ to $\infty$ is divergent.
However, if we do
$$ \lim_{b\to\infty} \int_{-b}^{b} \frac{2x}{x^2+1} \,\mathrm{d}x = \lim_{b\to\infty} \ln \lvert b+1 \rvert -\ln\lvert -b+1\rvert = \lim_{b\to\infty} \ln\left\lvert \frac{b+1}{-b+1}\right\rvert = \ln \lvert -1\rvert = 0, $$
the integral is convergent.
How to explain these two different results?
The same thing occurs with $\int_{-\infty}^\infty x\,\mathrm dx$. This is why the definition of $\int_{-\infty}^\infty f(x)\,\mathrm dx$ involves the integrals $\int_a^\infty f(x)\,\mathrm dx$ and $\int_{-\infty}^af(x)\,\mathrm dx$ (the choice of $a$ doesn't matter): to avoid problems such as this one.