All,
I am currently working on core
Java hibernate 3 tier application (controller -> service ->dao ->orm)
All transactions incept at the service layer. The controller coordinates the entire flow of events (i.e. invoking the right service layer components) for handling an incoming request.
We are not using any checked exceptions. All exceptions within the app are runtime exceptions. And there is only one catch block at the controller layer for trapping all runtime exceptions.
In this catch block at the controller layer we have a dedicated exception handler utility which logs/persists the exception details. My question is related to Hibernate transactions and exception handling.
Say a particular transaction commit fails or say there is a failure even before commit. This exception propagates back to the controller layer wherein we have the runtime exception handler. Here the first thing I do is rollback the transaction and then proceed with logging of the exception details.
The reason I am not creating individual try/catch blocks is some events are crucial and in the event of failure related to these we need to halt the execution and provide appropriate failure details.
For other non-crucial errors we suppress the exceptions in a catch block.
I would like to know your thoughts on this approach of using runtime exceptions throughout and having a single catch for handling all runtime exceptions.
Thanks - Mohit