Add hook for customizing exceptions

The exceptions can be customized via a new ErrorHandler class, which is
responsible for returning customized exceptions during synchronous
requests.
Forbid returning null from error handler.

A bunch of code style and test clean-up as well.
Code style cleanup.