struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "HG" <str...@nospam.websolver.dk>
Subject Re: Struts Exception Handling
Date Mon, 01 Dec 2003 08:53:30 GMT
Hi Baljinder

I use one common rule of thumb in regard to exception handling in Struts
applications: "Never throw an exception in action classes, always catch
exceptions in action classes"

At lower layers (Business Delegate, EJB Facade, Data Access Object, etc) I
COULD use exceptions to communicate errors to upper layers (Actions).
I used the above scenario in several projects, but I also did projects where
I never rethrow a catched exception, instead I return some sort of
"errorcode".

Anyone else can share their experience...I saw an article discussing this on
theserverside.com for a while ago...quite good...maybe you should check it
out.

Best regards

Henrik

----- Original Message ----- 
From: "Baljinder Singh" <baljinder.singh@interglobetechnologies.com>
To: "Struts Users Mailing List" <struts-user@jakarta.apache.org>
Sent: Monday, December 01, 2003 9:30 AM
Subject: RE: Struts Exception Handling


> 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:baljinder.singh@interglobetechnologies.com]
> 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:MMainguy@kmart.com]
> 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:baljinder.singh@interglobetechnologies.com]
> 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: struts-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: struts-user-help@jakarta.apache.org
>
> -----------------------------------------
> 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: struts-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: struts-user-help@jakarta.apache.org
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: struts-user-help@jakarta.apache.org
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: struts-user-help@jakarta.apache.org
>


---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org


Mime
View raw message