To add to the excellent answers of jvp and David Speyer above:

Actually Hartog's theorem does even better: Given a domain $U\subset\mathbb{C}^{n{\geq{2}}}$ and a compact $K\subset{U}$ such that $U\setminus{K}$ is **just connected**, any holomorphic function on $U\setminus K$ extends holomorphically to $U$. Note that we don't need the codimension condition. This is actually a simple consequence of Cauchy's formula in several variables.

For algebraic geometry (resp. complex geometry) and dimension $\geq{2}$: The analog of Hartog's theorem is that any regular (resp. holomorphic) function on the complement of an algebraic (resp. analytic) subset of codimension atleast $2$ in a normal algebraic(resp. analytic) variety, extends to the whole algebraic (resp. analytic) variety.

I would also like to point out the important difference between the affine (resp. Stein) case and the projective case as perhaps alluded to by jvp above. If $X$ is a projective algebraic variety over $\mathbb{C}$ and you find a holomorphic function $f$ on the complement of a divisor $D$ then you will not be able to extend the function to all of $X$ however hard you try(!) since there are no global non-constant functions on projective varieties (similar statement for compact analytic vars). So to add to jvp's answer (which might seem like hair-splitting but is important IMHO): His second paragraph must refer to a non-projective neighborhood of the contractible curve that he discusses, otherwise the argument is still true but only vacuously! This is because there is no non-constant function to be found on a projective surface on the complement of a contractible curve and hence there is nothing to extend!

Moreover, it will not be possible in general to extend holomorphic functions from the complement of divisors whose examples can be easily constructed. So there is no hope in this direction without any local boundedness hypothesis.