Properly encode unicode strings in exceptions.

Previously, if a non-ascii unicode string was in an exception,
we'd fail to encode the exception and crash.