Reading "Morse Theory" by J.Milnor I found more than once this way of approach:
Let X and Y be two topological space. Suppose we want to define a continuous map from a space obtained by attaching a n-cell to X along a map $\phi: S^{n-1}\rightarrow X$. Let's call $X\sqcup_{\phi} D^{n}$ this space, $i:X\rightarrow X\sqcup D^{n}$ and $j:D^{n}\rightarrow X\sqcup D^{n}$ the two inclusion maps and $\pi:X\sqcup D^{n}\rightarrow X\sqcup_{\phi} D^{n}$ the natural projection. Additionally, suppose we know two continuous functions $f:X\rightarrow Y$ and $g:D^{n}\rightarrow Y$ such that the function $F:X\sqcup_{\phi} D^{n}\rightarrow Y$ defined by cases:
$F(\pi(i(x)))=f(x)$ if $x\in X$.
$F(\pi(j(x))=g(x)$ if $x\in D^{n}$
is well defined.
My problem concerns the proof of the continuity of the function: The book doesn't say anything about how to prove the continuity of the function defined this way. I tried to give an answer by applying pasting lemma: if I show that both the sets in which we defined F are closed, it follow the desired result. $\pi^{-1}\{\pi(i(x)): x\in X\}=\{(i(x)): x\in X\}\cup S^{n-1}$ is obviously a closed subspace of $X\sqcup D^{n}$, while I'm not able to say much about $\pi^{-1}\{\pi(j(x)):x\in D^{n}\}=j(D^{n})\cup i(\phi(S^{n-1}))$. If X is Hausdorff $\phi(S^{n-1})$ is closed in X and so $j(D^{n})\cup i(\phi(S^{n-1}))$ is closed in $X\sqcup D^{n}$ but in general I don't know how to prove it and in Milnor's book there aren't any hypothesis on X.
Can someone give me an hand? :)
Thanks in advance!