You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Baljinder Singh <ba...@interglobetechnologies.com> on 2003/12/01 09:30:43 UTC

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


Re: Drop-down-list

Posted by Gede Indrawan <ge...@gratika.co.id>.
Hi Firat, thanx for the response,

But in more spesific case, consider I have 2 bussiness object:
- Machine contains property: int machineId, String machineName
- Location contains property: int locationId, String locationName,
Collection machines (instatiated as new ArrayList() contains Machine(s))

I have Collection locations (instantiated as new ArrayList() contains
Location(s)) with data from database and save it to the request or session,
and has listed successfully at drop down list using code below at jsp page.

<tr>
<td><bean:message key="addLogBook.location" /></td>
<td>
<html:select name="logBookForm" property="location.locationId">
<html:options collection="locations" property="locationId"
labelProperty="locationName"/>
</html:select>
</td>
</tr>

How can I make the second drop down list dynamically changes depend on what
Item selected at first drop down list?
The second drop down list contains Collection machines of Location.

Notes: logBookForm I configured as DynaValidatorForm.

Thanx for your help guys.
-GI.

----- Original Message -----
From: "Firat TIRYAKI" <fi...@pleksus.com.tr>
To: "Struts Users Mailing List" <st...@jakarta.apache.org>
Sent: Monday, December 01, 2003 5:44 PM
Subject: Re: Drop-down-list


> You can directly do it using javascript, refer to the below URL for a
> detailed example
>
> http://www.jguru.com/faq/view.jsp?EID=923880
>
> F.
>
> ----- Original Message -----
> From: "Gede Indrawan" <ge...@gratika.co.id>
> To: "Struts Users Mailing List" <st...@jakarta.apache.org>
> Sent: Monday, December 01, 2003 12:39 PM
> Subject: Drop-down-list
>
>
> > Hi all,
> >
> > In case I have 2 drop-down-lists and the second drop-down-list content
> > changed automatically if we select certain item at the first one,
> > how can I do it in the struts world? Any references to this case? Any
code
> > example?
> >
> > I am totally blind to this case..
> >
> > best regards
> > -GI.
> >
> >
> > ---------------------------------------------------------------------
> > 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


Re: Drop-down-list

Posted by Firat TIRYAKI <fi...@pleksus.com.tr>.
You can directly do it using javascript, refer to the below URL for a
detailed example

http://www.jguru.com/faq/view.jsp?EID=923880

F.

----- Original Message ----- 
From: "Gede Indrawan" <ge...@gratika.co.id>
To: "Struts Users Mailing List" <st...@jakarta.apache.org>
Sent: Monday, December 01, 2003 12:39 PM
Subject: Drop-down-list


> Hi all,
>
> In case I have 2 drop-down-lists and the second drop-down-list content
> changed automatically if we select certain item at the first one,
> how can I do it in the struts world? Any references to this case? Any code
> example?
>
> I am totally blind to this case..
>
> best regards
> -GI.
>
>
> ---------------------------------------------------------------------
> 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


Drop-down-list

Posted by Gede Indrawan <ge...@gratika.co.id>.
Hi all,

In case I have 2 drop-down-lists and the second drop-down-list content
changed automatically if we select certain item at the first one,
how can I do it in the struts world? Any references to this case? Any code
example?

I am totally blind to this case..

best regards
-GI.


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


Re: Struts Exception Handling

Posted by HG <st...@nospam.websolver.dk>.
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" <ba...@interglobetechnologies.com>
To: "Struts Users Mailing List" <st...@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


RE: Struts Exception Handling

Posted by jacob hookom <ho...@yahoo.com>.
I just picked up the new Core J2EE 2nd Ed. book and it
mentions this issue.  To summarize, any errors from
the database (SQL exceptions) should be considered
"compile-time" errors, and should be resolved as being
fatal to the program's successful operation.

In all my action code, i do a try/catch (Throwable) to
make sure I don't let any exceptions leak to the UI
that I don't want to.  In the cases of unhandled
exceptions, I let the catch(Throwable) log the error,
and then throw a "SystemException" which is handled by
an exception handler to show a technical difficulties
page.

Jacob Hookom


--- Baljinder Singh
<ba...@interglobetechnologies.com> wrote:
> 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
> 


__________________________________
Do you Yahoo!?
Free Pop-Up Blocker - Get it now
http://companion.yahoo.com/

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