If the composition of two functions is continuous and one of those functions is continuous, is the other function continuous as well?

I have the following problem: Let $(X, d_X), (Y, d_Y)$, and $(Z, d_Z)$ be metric spaces, and $f:X \rightarrow Y, g:Y \rightarrow Z$ and $h:X \rightarrow Z, h=g \circ f$. We proved that if $f$ and $g$ are continuous, then $h$ is continuous. Suppose $f$ and $h$ are continuous. Does it follow that $g$ is continuous? Suppose that $g$ and $h$ are continuous. Does it follow that $f$ is continuous?

This is my solution: Let $X, Y, Z = \mathbb{R}$ and let each of their metrics be the absolute value metric. If $f(x) = ln(x)$, $g(x) = e^x$, then $h(x) = x$. While $g$ and $h$ are continuous, $f$ is not. Also, if we define $f(x) = e^x$, $g(x) = ln(x)$, $h(x) = x$, then $f$ and $h$ are continuous while $g$ is discontinuous.

However, I just realized that there might be a problem with my functions, because $ln(e^x) = x$ only on a positive interval. Now I'm having doubts whether or not there actually exist functions that satisfy the given condition. Is it just that I chose functions that are incorrect, or should I actually be proving the proposition instead of trying to disprove it?

Edit: I think the commentators might be misunderstanding my question. I know that $g \circ f$ is continuous, I just want to know if $g \circ f$ and $f$ being continuous implies that $g$ is continuous.

Second edit: I understand now, my bad.

• They understood perfectly, indeed take $g(x) = 1$ for $x \ge 0$, $g(x) = 0$ otherwise and let $f(x) = 1$ for every $x$. The composition is continuous, $f$ is continuous, but $g$ is not continuous. – Giovanni Sep 9 '15 at 2:41

That is false: if one of $f$, $g$ is constant, it is continuous and the composition $g\circ f$ is continuous since it is constant, even if the other function is not continuous.
No. If $g$ is a constant function, $g \circ f$ is continuous for any $f$.