hi viral,

You are thinking in the right direction. That's the way i do it.

I have got 2 base exception classes. AppException and AppRuntimeException.

1. The exceptions that come under the purview of the business logic and
these can be handled somehow at the controller/model layer to alter the flow
of control MUST extend AppException.

2. The exceptions that does not come under the purview of the business logic
and raise because of the system or network problems MUST extend
AppRuntimeException.

However, one must use some common sense to decide which exception should go
where.
Say, we are connecting to some URL and it may throw TimeoutException. which
is not a checked exception. We must be ready to capture this and throw some
checked exception.
The caller may catch the exception and try connecting again....may be thrice
;-) and if still no luck the caller passes on the message to PRESENTATION.

So your code will not be cluttered with "throws XRuntimeException" and
tthese exceptions MUST be handled back at CONTROLLER layer only. MODEL layer
should just handle CHECKED exceptions.

Examples
At Controller  => DuplicateEmailException extends AppException (we may
display the same form showing error on top)
At Model => InsufficientBalanceException extends AppException (we may charge
as much as he has got and rest of the amount we will accomodtae in next
invoice)

DatabaseAccessException extends AppRuntimeException ( as there is hardly
anything we can do about this. We MAY show some nice "SORRY" page and/or may
LOG this exception somewhere)

BTW, there is some nice article on "Exception handling" on IBM Developer
site. Do check.

hope this helps and suggestions are welcome.
Navjot Singh


  -----Original Message-----
  From: Viral_Thakkar [mailto:[EMAIL PROTECTED]
  Sent: Monday, September 01, 2003 5:50 PM
  To: Struts Users Mailing List
  Subject: Exception framework Usage


  Hi,



  Please suggest the exception framework in a scenario in a following
scenario.



  Struts Action class  a Business Delegate --> EJB a OR Mapping (Top link) a
Domain classes



  Please validate the below lines.



  There will be three layers at which we need to handle the exception.



  At EJB layer, at business delegate and at struts layer.



    1.. EJB layer (session bean) methods will throw the (Application)
business exceptions along with RemoteException. In the catch block it will
throw the EJBException (in case of checked system exceptions like
NamingException).
    2.. At business delegate layer, we will throw the application exceptions
in the catch block rather than EJBException to decouple the web layer and
EJB layer.
    3.. At struts layer, in the Action class's execute(), we will catch all
these business exceptions.


  Please provide your valuable inputs.



  Thanks in advance.
























Reply via email to