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.
James,Thanks for clarifying on that part of the post.
But my question was more towards the centralized exception handling approach and resorting to using java runtime exceptions only.
Does it make sense to avoid all exception handling in the lower layers (dao [integration], services [business]) and have single handler at the controller [presentation] layer.
The reason I brought in the Hibernate ORM specific question is we have a Hibernate rollback operation within the centralized exception handler.
We have a generic exception handler class which has the responsibility of dealing with runtime exceptions (logging, persisting to the database).
This exceptionHandler gets invoked only from one place (i.e. controller) in the event of any runtime exception so it does not belong to the controller layer as such.