Yes, it can be convex. Take f(x) = |x|. It is a piecewise convex function, and overall, convex. Similarly, g(x) = -|x| is piecewise convex but not convex overall, when you consider the linear sections together.
Convex (or concave) funtions are continuous over the relative interior of their domain. A discontinuous function could not be convex nor concave on all of its domain - but it can of course be piecewise convex (or concave) over it's continuity regions.
Ralf Gollmer : Your assertion is not true. For example, let us take any discontinuous linear functional whose domain is the whole vector space (e.g., see https://en.wikipedia.org/wiki/Discontinuous_linear_map#A_concrete_example ). Such a function is convex, has the whole space as its domain, and it discontinuous. Additionally, even in the finite dimensions, I would use "effective domain" instead of "domain" to avoid possible confusion.
I'm sorry to have dropped an important assumption: the assertion is true in R^n, which in many cases is the space for finite-dimensional optimization problems.
Wrt. the notion of effective domain I agree with you.