Is anybody having any comments on exception handling strategies ?? I am
looking for solutions reagarding handling exceptions related to database.

Thanks,
BS

-----Original Message-----
From: Baljinder Singh
[mailto:[EMAIL PROTECTED]
Sent: Wednesday, November 26, 2003 11:44 AM
To: Struts Users Mailing List
Subject: RE: Struts Exception Handling


Phil & Mike,

The approach that I am using right now is to make an ExceptionHandler and
configure it in struts-config.xml using something like following:

<global-exceptions>
                <exception type="java.sql.SQLException"
                        key="error.exception.SQL"
                        handler="com.exception.MyExceptionHandler"
                        path="error.jsp" />
<global-exceptions>

This way it would catch ALL database related exceptions and throw them. But
the problem goes deep into into handling a specific database exception, for
ex. duplicate key exception during insert operation or child dependency
during delete operation. Now different databases would throw different kind
of errors for these cases. My problem is how to catch these specific SQL
errors and show a user friendly message according to each of them. For ex,
when duplicate key exception is thrown, I want to show a message like
"Duplicate key cannot be inserted" or show a message like "Child record
exists for this key" for a child dependency case. How can I catch particular
error codes or message thrown by the database and show them and STILL KEEP
EVERYTHING GENERIC so that tommorrow if I change my database, I only need to
change the DAOs.

Thanks & Rgds,
BS

-----Original Message-----
From: Mainguy, Mike [mailto:[EMAIL PROTECTED]
Sent: Wednesday, November 26, 2003 2:11 AM
To: 'Struts Users Mailing List'
Subject: RE: Struts Exception Handling


Welll,
  The way I've done this before is to wrap all Exceptions in a Custom type
and throw it all the way back to struts.  This seems to work well for
trivial business style apps, I'm not sure how it would hold up in something
with more complexity in the business layer.  For example, My CRUD code would
catch SQL exceptions, check out what the real problem is, and, if it is a
genuine problem, throw a new FrameWorkException with the proper error
message (or message key) contained in it.

  I would also be curious on how other folks do such things however...


worse is better

-----Original Message-----
From: Baljinder Singh [mailto:[EMAIL PROTECTED]
Sent: Tuesday, November 25, 2003 9:55 AM
To: Struts Users Mailing List
Subject: Struts Exception Handling


Hi All,

I am looking for a robust exception handling approach in struts. Can
somebody help me in that. My framework consists of struts interacting with
session beans which then interact with DB through DAO. Now if during a CRUD
operation, for example there is a duplicate key exception thrown, how should
I handle it so that I can show the user exact message that duplicate key is
being inserted. Same for all kind of database messages and validations.

Thanks & Regards,
BS


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

-----------------------------------------
This message and its contents (to include attachments) are the property of
Kmart Corporation (Kmart) and may contain confidential and proprietary
information. You are hereby notified that any disclosure, copying, or
distribution of this message, or the taking of any action based on
information contained herein is strictly prohibited. Unauthorized use of
information contained herein may subject you to civil and criminal
prosecution and penalties. If you are not the intended recipient, you should
delete this message immediately.


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to