Add hook for customizing exceptions

The exceptions can be customized via a new ErrorHandler class, which is
responsible for throwing customized exceptions during synchronous
requests, or calling an appropriate callback method for asynchronous
requests.