Where is the flaw in my proof that the union of two continuous functions is continuous? 
Problem.
  Let $f:A\to\mathbb{R}$ be a continuous function on $A$ and $g:B\to\mathbb{R}$ be a continuous function on $B$ such that $A\cap B=\emptyset$. Let $h:A\cup B\to\mathbb{R}$ be defined by, $$h(x)=\begin{cases}f(x)& x\in A\\ g(x)& x\in B\end{cases}$$Is $h$ continuous on $A\cup B$?
Proof. Let $(x_n)_{n\ge1}$ be any sequence from $A\cup B$ converging to $c\in A\cup B$. Let us now form two subsequences of $(x_n)_{n\ge1}$, namely $(y_n)_{n\ge1}$ and $(z_n)_{n\ge1}$ such that $y_n\in A$ and $z_n\in B$ for all $n\in \mathbb{N}$. 
Then clearly $(h(y_n))_{n\ge1}\to h(c)$ since $h(y_n)=f(y_n)$ for all $n\in\mathbb{N}$ and $(h(z_n))_{n\ge1}\to h(c)$ since $h(z_n)=g(y_n)$ for all $n\in\mathbb{N}$. Consequently $(h(x_n))_{n\ge1}\to h(c)$ and we are done.

But the problem is that when I told our professor about this proof he told me that there should be some other conditions. But the argument seems to work well. Where is the flaw (if any) in my argument? 
 A: Take $A = [-1, 0)$ and $B = [0, 1]$ and take $f(x) = -1$ and $g(x) = 1$, then your function $h$ is not continuous at $0$. Taking $x_n = -1/n$, $x_n \to 0$, but $h(x_n) \to -1 \neq h(0)$.
Your conjecture could be repaired in various ways. E.g., it is true if $A$ and $B$ are required to have disjoint closures. However, your line of proof would have to be that because $A$ and $B$ have disjoint closures, if $x_n$ is sequence in $A \cup B$ that converges to a point $x \in A$ (resp. $B$), then for all large enough $n$, $x_n \in A$ (resp. $x_n \in B$). I.e., one of your subsequences $y_n$ and $z_n$ would be finite.
The condition that $A$ and $B$ have disjoint closures, i.e., that $\overline{A}\cap\overline{B} = \emptyset$, can be relaxed to $A \cap \overline{B} = \overline{A} \cap B = \emptyset$. This weaker condition is necessary as well as sufficient: if either $A \cap \overline{B}$ or $\overline{A} \cap B$ is non-empty, then with $f$ and $g$ constant functions with different values, you get a counterexample.
A: Here is a counter-example. Take $$f(x)=0, g(x)=1, A=[0,1/2), B=[1/2,1].$$ Then $h$ is clearly not continuous at $1/2$.
A: Here's an exotic counter example which I think illustrates the problem nicely
Let $f: \mathbb{Q} \to \mathbb{R}$ by $f(x) = 0$, and $g: \mathbb{R} \setminus \mathbb{Q} \to \mathbb{R}$ by $g(x) = 1$.  Then, $h = f\cup g$ is given by
$$h(x) = \begin{cases} 1 & x \not\in \mathbb{Q}\\ 0 & x \in \mathbb{Q}\end{cases}$$
and $h$ is discontinuous everywhere!
To see why, let's consider the sequence $(x_n)_{n\ge 1}$ given by $x_{2n-1} = \frac{1}{n}$ and $x_{2n} = \frac{\sqrt{2}}{n}$.  This sequence converges to $0$.  At any even indexed term, $h(x_n) = g(x_n) = 1$, but at the odd indexed terms, $h(x_n) = f(x_n) = 0$.  The problem occurs because there are infinitely many points of the sequence in each of $A$ and $B$.  The sequence cannot converge to any number (in particular, it cannot converge to $h(0)$).
There are various ways to restrict either the domains of the functions or the functions themselves so that the result become true.  For example, if we require that $\lim_{y \to x} f(y) = \lim_{y \to x} g(y)$ for every $x \in \overline{A} \cap \overline{B}$, the $h$ is continuous (and using Rob Arthan's observation in the last paragraph of his answer, we can weaken the requirement to the limits of $f$ and $g$ agreeing for any $x \in (\overline{A} \cap B) \cup (A \cap \overline{B})$).
A: As is often the problem in mathematical proofs, there's an issue immediately after you write "clearly"; you only know that $(h(y_n))_{n\geq0} = (f(y_n))_{n\geq0}$, and we don't necessarily know what $(f(y_n))_{n\geq0}$ converges to (if at all!). By saying $h(y_n) \to h(c)$, you implicitly said that $f(y_n) \to f(c)$ but what if $c \in B$ (or neither $A$ nor $B$)?
A: Suppose there are two constant functions: $f: (-\infty,0] \to \{0\}$ and $g: (0, \infty) \to \{1\}$. Can you see where your reasoning fails?
