In definite integration, do I have to watch out for the behaviour of a function between the limits? 
Calculate -
$$\int^{1}_{-1}\frac{e^\frac{-1}{x}dx}{x^2(1+e^\frac{-2}{x})}$$

This is my approach-
Substitute $t=e^\frac{-1}{x}$
$$\therefore \int^{\frac{1}{e}}_{e}\frac{dt}{1+t^2}$$
which gives us $\frac{\pi}{2}- 2\arctan{e}$, but the answer given is $\pi- 2\arctan{e}$. I'm guessing that my wrong answer has something to do with the exponential term.
 A: You're pretty much correct. The usual theorem for integration by substitution says that we can use a substitution $t=\phi(x)$ if $\phi$ is $C^1$ (continuously differentiable) in the interval of integration. (This is just a sufficient condition of course).
But your substitution $t=\phi(x)=e^{-\frac 1x}$ is not even continuous at $x=0$. In fact
$$
\lim_{x\to0^-} \phi(x) = \infty
$$
$$
\lim_{x\to0^+} \phi(x) = 0
$$
So we have to split the integral up like this:
$$
\int_{-1}^0 \frac{e^{-\frac{1}{x}}}{x^2(1+e^{-\frac{2}{x}})} dx
= \int_e^\infty \frac{1}{1+t^2} dt
= \arctan{\infty} - \arctan e 
= \frac{\pi}{2} - \arctan e
$$
and
$$
\int_0^1 \frac{e^{-\frac{1}{x}}}{x^2(1+e^{-\frac{2}{x}})} dx
= \int_0^{e^{-1}} \frac{1}{1+t^2} dt
= \arctan{e^{-1}} - \arctan 0
= \frac{\pi}{2} - \arctan e
$$
so
$$
\int_{-1}^1 \frac{e^{-\frac{1}{x}}}{x^2(1+e^{-\frac{2}{x}})} dx
= \pi - 2\arctan e
$$
Bottom line: If $\phi$ is not continuous (or $C^1$, but that would be rarer) on the interval, then split the interval up.
BONUS: In this case we could also have taken a common short cut. We can notice that $f(x) = \frac{e^{-\frac{1}{x}}}{x^2(1+e^{-\frac{2}{x}})}$ is an even function (i.e. $f(x)= f(-x)$). Therefore we can also write
$$
\int_{-1}^1f(x)dx = 2\int_{0}^1 f(x)dx
$$
and then the substitution is legal again.
A: The answer to the question in the header is yes, and this is a really interesting example.
When you substitute a variable, the substitution applies to the whole interval of integration. If you say $t=e^{\frac{-1}{x}}$, you mean that all the values that $x$ takes on are related to the values that $t$ takes by that relation. Really you're applying the function $e^{\frac{-1}{x}}$ to the whole interval of the $x$'s, i.e. $[-1,1]$. Normally, when we do substitution the function you use maps an interval to an interval, so it suffices to just look at the endpoints. Not so with this function! What is the image of $[-1,1]$ under $e^{-\frac1{x}}$? It's $[0,\frac1e]\cup [e,\infty]$, which you can see in a number of ways, e.g. the image of $[-1,1]$ under $1/x$ is $[-\infty,-1]\cup [1,\infty]$, then map it through $e^{-x}$ to get the right interval. Thus the correct substitution ought to be \begin{eqnarray}
&&\int_{-1}^1\frac{e^{-\frac1x}}{x^2(1+e^{-\frac2x})}dx = \int_{[0,\frac1e]\cup [e,\infty]} \frac1{1+t^2} dt = \int_0^{\frac1e} \frac1{1+t^2} + \int_e^\infty \frac1{1+t^2} dt\\ &=& \arctan{\frac1e} - \arctan0 + \arctan{\infty} - \arctan{e} = \arctan\frac1e + \frac\pi2 - \arctan(e) \\&=& \pi-2\arctan(e)
\end{eqnarray}
A: You can start from the substitution $\;y=-\dfrac1x.\;$ Then
$$I=\int\limits_{-\infty}^{-1}\dfrac{e^y\,\text dy}{e^{2y}+1}
+\int\limits_1^\infty\dfrac{e^y\,\text dy}{e^{2y}+1}
= \int\limits_1^\infty\dfrac{e^{-y}\,\text dy}{e^{-2y}+1} 
+ \int\limits_1^\infty\dfrac{e^y\,\text dy}{e^{2y}+1} 
= 2\int\limits_1^\infty\dfrac{e^y\,\text dy}{e^{2y}+1} $$
$$= 2\int\limits_e^\infty\dfrac{\text de^y}{1+e^{2y}}
=2\arctan e^y\bigg|_1^\infty =\pi-2\arctan e,$$
without doubts in the result.
