Can the expectation of a random variable not exist? I saw a question like this.

Solving that was not hard, because it only needs to show that the value of the next improper integral does not exist.
$$
\int_0^\infty x\cdot\frac{2}{\pi(1+x^2)}dx=\infty
$$
It is understandable by formula, but not intuitively at all. From what I've learned so far, every random variable has an expectation, and any book never said that the average may not exist.
Can this actually be? Of course, it is certain that a given function satisfies the definition of a random variable. But what does it mean that the expectation of a random variable does not exist?
 A: Your question is not really about mathematics, but more about philosophy!
You asked : But what does it mean as a probability variable that the mean does not exist?
I think that the answer to the question is mainly about asking you in reverse: what do you mean by what does it mean...? Answering that will be very interesting!
The issue may come from the fact that in initial courses about random variables, we start with random variables taking a finite number of values, like dice. In that case, the mean always exists.
With random variables taking an infinite number of values, things are different.
A: Sometimes, continuous variables can be too abstract to communicate fundamental concepts like this. To consider a more concrete example, consider a discrete random variable $X$ that takes on the value $2^n$ with probability $1/2^n$ for $n \in \{1, \dots\}$. In other words, you flip a coin until its first occurrence of heads; if $N$ denotes the number of flips required, then $X = 2^N$.
Since the expected value of a discrete variable is $\sum_x x \cdot p(x)$, we see that  $$\mathbb E[X] = \sum_{x \in \{1, \dots \}} 2^x \cdot \frac{1}{2^x} = \sum_{x \in \{1, \dots\}} 1 = \infty$$
which doesn't "exist" in the sense that it is not a finite number, just like your example.
Why it matters: one of the duties of a theoretical mean is to be the long-run convergence point of repeated trials of a random variable. For instance, if you average 100 $\operatorname{Norm}(0, 1)$ variables together, you'll get something pretty close to 0; if you average 10000 of those variables together, you'll get something closer yet to 0. But if you try the same tactic with either your Cauchy variable, or the variable $X$ I described, you'll find that the sample average fluctuates wildly upon repeated averages, and that it does not tend to any particular value as you increase the number of things you average together.
As for why you haven't seen this concept in your books -- it's just an omission, pure and simple. Those books ought to have mentioned it, at least in passing.
A: The density you have given belongs to the Cauchy distribution and indeed, this distribution does not have a population mean, i.e., expected value, in the sense that you have shown.
However, a sample of $n<\infty$ independent Cauchy variables $[x_1,x_2,...,x_n]$ does have a well-defined average which is given by $\bar{x}=\frac{1}{n}\sum_{j=1}^{n}x_i$. Nothing prevents this average $\bar{x}$ from existing since $\bar{x}$ is not the expected value or anything special - it is just the sample average, and in fact we have $\bar{x}\sim\text{Cauchy}(x_0,\gamma)$ which means that taking the average of a sample from the pdf you gave is essentially the same thing as drawing another random sample from that distribution up to a constant scaling.
The fact that the population mean does not exist suggests that computing the expected value of your pdf does not give you an indicator of where the density is located. You can obtain this by computing the median or mode of your pdf, which is $0$ in both cases.
