I don't really understand why a discontinuous function cannot be differentiable.
In Stewart's Calculus, the definition of a function $f$ being differentiable at $a$ is that $f'(a)$ exists. Earlier it gives the definition of the derivative as $f'(x)=\lim_{h\to0}\frac{f(x+h)-f(x)}{h}$. It also has a theorem that if $f$ is differentiable at $a$, then $f$ is continuous at $a$. There is also a definition that a functions $f$ is continuous at a number $a$ if $\lim_{x\to a}f(x)=f(a)$.
Take for example the very simple function:
$$ f(x)=\begin{cases} x+1 & x\geq0, \\ x & x<0. \end{cases} $$
It is discontinuous at $x=0$ (the limit $\lim_{x\to 0}f(x)$ does not exist and so does not equal $f(0)$), but if I find the derivative using the limit above, I get the left and right limits to equal $1$. So therefore, the derivative exists.
According to the book, the function shouldn't be differentiable at $x=0$ as it has a discontinuity (continuity is a necessary condition of differentiability). What am I doing/understanding wrong?