Changed the exception handler to allow for entity-based exception handling