We are designing an application that will be developed using JSP + EJB .
To deal with the exception part, we have thought about following solutions
(1)All methods in EJB will be declare with throws clause, with the respect to the potential exceptions that can be thrown by method. We will catch only those exceptions, for which we can take alternative steps or further action when they occurred. All other exceptions will be thrown to the caller.
(2)All JSP pages will have try/catch that catches exceptions thrown by EJB or by JSP code.
(3)A common JSP file will be designated to handle Exception by setting isErrorPage property true and all JSP files are pointing to that particular file for exception handling.
(4)Whenever any exception occurred in application, it will bubbled up and end user will get a common JSP page designed to handle exception.
I am looking for the suggestions to improve this mechanism.
Can I clarify a few things that you are probably planning to do (assuming that the client is remote).
If the EJB catches or creates an application exception, the EJB will throw it as an application exception and the client will handle it (do some recovery operation).
If the EJB is in a transaction context and catches an application exception which makes it a nonsense to continue the transaction, the EJB will call setRollback() and then throw the application exception.
If the EJB catches an exception which the client does not expect or cannot recover from, eg SQLException, it will wrap it and rethrow it as an EJBException.
If a RuntimeException is created in the EJB, the EJB will allow it to propagate to the container (which will then throw a RemoteException to the client).