Added error handler to throw ErrorException when it triggers.