Let $X$ be a random variable such that $\Bbb P(X=\infty)=1$ for example $X=\sum^\infty_{k \geq 0} \Bbb 1_{X_k=x}$ where $X_k$ is a random walk started at $x \in \Bbb Z^2$ (recurrent walk).
How is its expectation defined ? I had two ways to see it but they disagree
Since $$E(X)=\sum_{k=0}^\infty kP(X=k) = \lim_{n \to \infty } \sum_{k=0}^n kP(X=k) =\lim_{n \to \infty } \sum_{k=0}^n k .0 =0$$ This definition does not take in account the fact that $X$ can be $\infty$. On the other hand,
$$ E(X)=\int XdP=\infty$$
Or is it simply undefined ?
The definition of the expectation of a nonnegative random variable $X:\Omega\to\mathbb R_+\cup\{+\infty\}$ is $$ \mathbb E[X]=\int_{\Omega}X(\omega)\,\mathbb P(d\omega)=\int_{\mathbb R_+\cup\{+\infty\}}x\,\mu(dx), $$ where $\mu$ denotes the distribution of $X$.
In the case where $X(\Omega)\subset\mathbb N$ you can indeed show that the formula above can be rewritten as $$ \mathbb E[X]=\sum_{k=0}^{+\infty}k\mathbb P(X=k). $$
However here you do not have $X(\Omega)\subset\mathbb N$, therefore you cannot apply the latter formula.
The expected value is still well defined, and is equal to $+\infty$. To see this, you can either say that $\int_{\Omega}X(\omega)\,\mathbb P(d\omega)=\int_{\Omega}(+\infty)\,\mathbb P(d\omega)=+\infty$. Or you can say that $\mu=\delta_{\{+\infty\}}$ so $\int_{\mathbb R_+\cup\{+\infty\}}x\,\mu(dx)=\int_{\mathbb R_+\cup\{+\infty\}}(+\infty)\,\mu(dx)=+\infty$.
PS: if $X(\Omega)\subset\mathbb N\cup\{+\infty\}$ you have $$ \mathbb E[X]=\sum_{k=0}^{+\infty}k\mathbb P(X=k) + (+\infty)\mathbb P(X=+\infty). $$