I recently came across this problem in class:
Determine whether $\int_{-\infty}^\infty\frac{x}{x^2+1}dx$ converges or diverges.
My first thought was that since $\frac{x}{x^2+1}$ is an odd function, and the integral is symmetric about the y-axis, then it must be 0. However, the answer said that it's wrong, and that the integral diverges, since both $\int_{0}^\infty\frac{x}{x^2+1}dx$ and $\int_{-\infty}^0\frac{x}{x^2+1}dx$ diverge. It then said it's wrong to say that since $\int_{-R}^R\frac{x}{x^2+1}dx = 0$, then $\int_{-\infty}^\infty\frac{x}{x^2+1}dx$ must also be 0. Why is this "wrong"?
By that logic, $\int_{-\infty}^\infty \sin(x)\mathrm{d}x = 0$, which there's no reason to assume should be true. Looking at $\lim_{r\to\infty}\int_{-r}^r f(x)\mathrm{d} x$ is known as the Cauchy Principle Value. Also, this answer talks about the distinction some more.
The reason they're different is we like $\int_a^c f(x)\mathrm d x = \int_a^b f(x)\mathrm{d}x+\int_b^cf(x)\mathrm{d}x$. This is now longer true if we evaluate the integral as you suggest. Instead, we define $\int_{-\infty}^\infty f(x)\mathrm{d}x = \lim_{m\to\infty}\lim_{n\to\infty}\int_{-n}^m f(x)\mathrm{d}x$. Now, we still have the property we want, and can simplify this further to: $$\lim_{n\to\infty}\int_{-n}^0 f(x)\mathrm{d}x+\lim_{m\to\infty}\int_0^m f(x)\mathrm{d}x$$ If both of these exist, we're fine. In your example, we get $\infty$ and $-\infty$ as the results, so adding them gives an indeterminant form, which we don't like.