Re: Where to catch/throw Exceptions in Struts Tiered Architecture

2003-04-05 Thread Navjot Singh
hi andrew and list,

I have another small Q on nested exception.

Consoder a nomal web scenario, where a request comes to Action, delegated to
Business logic class, that class queries database and follows the path back.

CustomerAction  - Customer -- JDO etc.
   |   ReqFailException DataException
  V
   ReqFailHandler global-exception
   |
  V
   reqfail .jsp

As most(can we say All) of the requests go up to database and any method can
throw exception. SO...
This simple flow cleary shows that EVERY method in _JDO_ MUST be throwing
DataException that CAN be *catched* by _Customer_ and consequently EVERY
method in Customer WILL *throw* nested ReqFailException.

PunchLine: Every method is throwing _exception_ to it's caller.

Note that 2-3 methods in Customer MAY throw additional exception but
ReqFailException will ALWAYS be thrown to Action class.

Is that OK in normal practices?

Looking forward to some replies.
-Navjot Singh
PS - May be i will understand it' use better if you can give me some sample
code ;-)

- Original Message -
From: Andrew Hill [EMAIL PROTECTED]
To: Struts Users Mailing List [EMAIL PROTECTED]
Sent: Thursday, April 03, 2003 5:02 PM
Subject: RE: Where to catch/throw Exceptions in Struts Tiered Architecture


 Generally, returning null when it should be an error is considered bad
 practice. (If null is a valid return value of course thats a different
 matter).
 In this case you should throw an exception and catch it in the calling
class
 and branch or throw again appropriately.
 You dont want your calling class to have to know about low level details
 like specific sql exceptions though, so instead of just letting the sql
 exception propogate upwards, you would catch it and throw a different more
 abstract exception (probably one you create yourself) up to the caller -
the
 caller shouldnt have to know the details about your persistence
mechanism -
 it just needs to know it failed - and sometimes needs to know if the
failure
 is fatal and any other pertinent info.
 The nested excpetion classes should also be able to keep a reference to
the
 exception they wrap so the stacktrace show all the exceptions in the
chain -
 useful when debugging.

 btw: If I recall rightly Ted Husted explains this 10 times better in one
 tenth the words in his book (struts in action)

 Have a look at these articles:

http://developer.java.sun.com/developer/technicalArticles/Programming/except
 ions/
 http://www-106.ibm.com/developerworks/java/library/j-ejb01283.html
 http://www.javaworld.com/javatips/jw-javatip91_p.html

 There was another very good one too - but it doesnt seem to be in my
 favourites list and I cant seem to find it now.


 -Original Message-
 From: Navjot Singh [mailto:[EMAIL PROTECTED]
 Sent: Thursday, 3 April 2003 18:53
 To: Struts Users Mailing List; [EMAIL PROTECTED]
 Subject: Re: Where to catch/throw Exceptions in Struts Tiered
 Architecture


 hi andrew,

 but surely these long stacktraces are not meant for users ;-)

 what i have got from your statement is something like this

 SQLException
 |__DatabaseException
 |ApplicationException

 finally, this ApplicationException is what is being thrown into execute()
 call.

 May i am novice, but I still need to be convinced about throwing so many
 exceptions in chain

 Can't the stuff be handled in a simple way --
 SAY
 a. when you get SQLException, catch and return NULL
 b. Calling Class __ifs__ for NULL instead of __catching__ and transfer the
 control accordingly.

 Is there something i am ignoring?

 regards
 Navjot Singh

 - Original Message -
 From: Andrew Hill [EMAIL PROTECTED]
 To: Struts Users Mailing List [EMAIL PROTECTED]
 Sent: Thursday, April 03, 2003 3:49 PM
 Subject: RE: Where to catch/throw Exceptions in Struts Tiered Architecture


 | I use nested exceptions, and virtually all my methods (and thus layers)
 | catch and wrap and throw...
 | Makes for some impressively long stacktraces - and is marvellous for
 | debugging! :-)
 |
 |
 | -Original Message-
 | From: Navjot Singh [mailto:[EMAIL PROTECTED]
 | Sent: Thursday, 3 April 2003 18:05
 | To: Struts Users List
 | Subject: Where to catch/throw Exceptions in Struts Tiered Architecture
 |
 |
 | Hi,
 |
 | Take a simple case.
 |
 |Action
 |   Y
 | UserAction - User - Database
 |   |
 |  V
 |   user.jsp
 |
 | Say, Database throws exception. What is best way to handle exception?
 |
 | 1. Catch in User class and return NULL / some ErrorObject to UserAction
 and
 | let UserAction decide how to handle it?
 |
 | 2. Let User class __pass on__ the Exception from Database to UserAction.
 |
 | 2a. As execute() is already throwing Exception so it will handle ALL so
 Set
 | global-exception handler that can send the user to some nice page?
 | 2b. Catch Exception in UserAction and then do some thing ...
 |
 | Which one do you guys follow in not-so-large scale web applications

RE: Where to catch/throw Exceptions in Struts Tiered Architecture

2003-04-03 Thread Andrew Hill
I use nested exceptions, and virtually all my methods (and thus layers)
catch and wrap and throw...
Makes for some impressively long stacktraces - and is marvellous for
debugging! :-)


-Original Message-
From: Navjot Singh [mailto:[EMAIL PROTECTED]
Sent: Thursday, 3 April 2003 18:05
To: Struts Users List
Subject: Where to catch/throw Exceptions in Struts Tiered Architecture


Hi,

Take a simple case.

   Action
  Y
UserAction - User - Database
  |
 V
  user.jsp

Say, Database throws exception. What is best way to handle exception?

1. Catch in User class and return NULL / some ErrorObject to UserAction and
let UserAction decide how to handle it?

2. Let User class __pass on__ the Exception from Database to UserAction.

2a. As execute() is already throwing Exception so it will handle ALL so Set
global-exception handler that can send the user to some nice page?
2b. Catch Exception in UserAction and then do some thing ...

Which one do you guys follow in not-so-large scale web applications?

would appreciate any comments.
-navjot singh




-
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]



Re: Where to catch/throw Exceptions in Struts Tiered Architecture

2003-04-03 Thread Gareth Andrew
IMO, catch the database exception in user, then throw a new (wrapped) 
exception, catch it in UserAction and throw a new exception, and use 
struts decalritive exception handling features to handle it.  This 
avoids undue coupling between UserAction, User and Database.

Gareth.

Navjot Singh wrote:

Hi,

Take a simple case.

  Action
 Y
UserAction - User - Database
 |
V
 user.jsp
Say, Database throws exception. What is best way to handle exception?

1. Catch in User class and return NULL / some ErrorObject to UserAction and
let UserAction decide how to handle it?
2. Let User class __pass on__ the Exception from Database to UserAction.

2a. As execute() is already throwing Exception so it will handle ALL so Set
global-exception handler that can send the user to some nice page?
2b. Catch Exception in UserAction and then do some thing ...
Which one do you guys follow in not-so-large scale web applications?

would appreciate any comments.
-navjot singh


-
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]


Re: Where to catch/throw Exceptions in Struts Tiered Architecture

2003-04-03 Thread Navjot Singh
hi andrew,

but surely these long stacktraces are not meant for users ;-)

what i have got from your statement is something like this

SQLException
|__DatabaseException
|ApplicationException

finally, this ApplicationException is what is being thrown into execute()
call.

May i am novice, but I still need to be convinced about throwing so many
exceptions in chain

Can't the stuff be handled in a simple way --
SAY
a. when you get SQLException, catch and return NULL
b. Calling Class __ifs__ for NULL instead of __catching__ and transfer the
control accordingly.

Is there something i am ignoring?

regards
Navjot Singh

- Original Message -
From: Andrew Hill [EMAIL PROTECTED]
To: Struts Users Mailing List [EMAIL PROTECTED]
Sent: Thursday, April 03, 2003 3:49 PM
Subject: RE: Where to catch/throw Exceptions in Struts Tiered Architecture


| I use nested exceptions, and virtually all my methods (and thus layers)
| catch and wrap and throw...
| Makes for some impressively long stacktraces - and is marvellous for
| debugging! :-)
|
|
| -Original Message-
| From: Navjot Singh [mailto:[EMAIL PROTECTED]
| Sent: Thursday, 3 April 2003 18:05
| To: Struts Users List
| Subject: Where to catch/throw Exceptions in Struts Tiered Architecture
|
|
| Hi,
|
| Take a simple case.
|
|Action
|   Y
| UserAction - User - Database
|   |
|  V
|   user.jsp
|
| Say, Database throws exception. What is best way to handle exception?
|
| 1. Catch in User class and return NULL / some ErrorObject to UserAction
and
| let UserAction decide how to handle it?
|
| 2. Let User class __pass on__ the Exception from Database to UserAction.
|
| 2a. As execute() is already throwing Exception so it will handle ALL so
Set
| global-exception handler that can send the user to some nice page?
| 2b. Catch Exception in UserAction and then do some thing ...
|
| Which one do you guys follow in not-so-large scale web applications?
|
| would appreciate any comments.
| -navjot singh
|
|
|
|
| -
| 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]



Re: Where to catch/throw Exceptions in Struts Tiered Architecture

2003-04-03 Thread Navjot Singh
thanks gareth, i got the point.
thanks to Ted (Tip 15) and Andrew as well.

-navjot

- Original Message -
From: Gareth Andrew [EMAIL PROTECTED]
To: Struts Users Mailing List [EMAIL PROTECTED]
Sent: Thursday, April 03, 2003 4:09 PM
Subject: Re: Where to catch/throw Exceptions in Struts Tiered Architecture


| IMO, catch the database exception in user, then throw a new (wrapped)
| exception, catch it in UserAction and throw a new exception, and use
| struts decalritive exception handling features to handle it.  This
| avoids undue coupling between UserAction, User and Database.
|
| Gareth.
|
| Navjot Singh wrote:
|
| Hi,
| 
| Take a simple case.
| 
|Action
|   Y
| UserAction - User - Database
|   |
|  V
|   user.jsp
| 
| Say, Database throws exception. What is best way to handle exception?
| 
| 1. Catch in User class and return NULL / some ErrorObject to UserAction
and
| let UserAction decide how to handle it?
| 
| 2. Let User class __pass on__ the Exception from Database to UserAction.
| 
| 2a. As execute() is already throwing Exception so it will handle ALL so
Set
| global-exception handler that can send the user to some nice page?
| 2b. Catch Exception in UserAction and then do some thing ...
| 
| Which one do you guys follow in not-so-large scale web applications?
| 
| would appreciate any comments.
| -navjot singh
| 
| 
| 
| 
| -
| 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]



RE: Where to catch/throw Exceptions in Struts Tiered Architecture

2003-04-03 Thread Andrew Hill
Generally, returning null when it should be an error is considered bad
practice. (If null is a valid return value of course thats a different
matter).
In this case you should throw an exception and catch it in the calling class
and branch or throw again appropriately.
You dont want your calling class to have to know about low level details
like specific sql exceptions though, so instead of just letting the sql
exception propogate upwards, you would catch it and throw a different more
abstract exception (probably one you create yourself) up to the caller - the
caller shouldnt have to know the details about your persistence mechanism -
it just needs to know it failed - and sometimes needs to know if the failure
is fatal and any other pertinent info.
The nested excpetion classes should also be able to keep a reference to the
exception they wrap so the stacktrace show all the exceptions in the chain -
useful when debugging.

btw: If I recall rightly Ted Husted explains this 10 times better in one
tenth the words in his book (struts in action)

Have a look at these articles:
http://developer.java.sun.com/developer/technicalArticles/Programming/except
ions/
http://www-106.ibm.com/developerworks/java/library/j-ejb01283.html
http://www.javaworld.com/javatips/jw-javatip91_p.html

There was another very good one too - but it doesnt seem to be in my
favourites list and I cant seem to find it now.


-Original Message-
From: Navjot Singh [mailto:[EMAIL PROTECTED]
Sent: Thursday, 3 April 2003 18:53
To: Struts Users Mailing List; [EMAIL PROTECTED]
Subject: Re: Where to catch/throw Exceptions in Struts Tiered
Architecture


hi andrew,

but surely these long stacktraces are not meant for users ;-)

what i have got from your statement is something like this

SQLException
|__DatabaseException
|ApplicationException

finally, this ApplicationException is what is being thrown into execute()
call.

May i am novice, but I still need to be convinced about throwing so many
exceptions in chain

Can't the stuff be handled in a simple way --
SAY
a. when you get SQLException, catch and return NULL
b. Calling Class __ifs__ for NULL instead of __catching__ and transfer the
control accordingly.

Is there something i am ignoring?

regards
Navjot Singh

- Original Message -
From: Andrew Hill [EMAIL PROTECTED]
To: Struts Users Mailing List [EMAIL PROTECTED]
Sent: Thursday, April 03, 2003 3:49 PM
Subject: RE: Where to catch/throw Exceptions in Struts Tiered Architecture


| I use nested exceptions, and virtually all my methods (and thus layers)
| catch and wrap and throw...
| Makes for some impressively long stacktraces - and is marvellous for
| debugging! :-)
|
|
| -Original Message-
| From: Navjot Singh [mailto:[EMAIL PROTECTED]
| Sent: Thursday, 3 April 2003 18:05
| To: Struts Users List
| Subject: Where to catch/throw Exceptions in Struts Tiered Architecture
|
|
| Hi,
|
| Take a simple case.
|
|Action
|   Y
| UserAction - User - Database
|   |
|  V
|   user.jsp
|
| Say, Database throws exception. What is best way to handle exception?
|
| 1. Catch in User class and return NULL / some ErrorObject to UserAction
and
| let UserAction decide how to handle it?
|
| 2. Let User class __pass on__ the Exception from Database to UserAction.
|
| 2a. As execute() is already throwing Exception so it will handle ALL so
Set
| global-exception handler that can send the user to some nice page?
| 2b. Catch Exception in UserAction and then do some thing ...
|
| Which one do you guys follow in not-so-large scale web applications?
|
| would appreciate any comments.
| -navjot singh
|
|
|
|
| -
| 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]


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



Re: Where to catch/throw Exceptions in Struts Tiered Architecture

2003-04-03 Thread Navjot Singh
thanks a ton.
now, i need to spend some hours doing some arrangements in my code but
anyway that's for my good  ;-)

-navjot singh
- Original Message -
From: Andrew Hill [EMAIL PROTECTED]
To: Struts Users Mailing List [EMAIL PROTECTED]
Sent: Thursday, April 03, 2003 5:02 PM
Subject: RE: Where to catch/throw Exceptions in Struts Tiered Architecture


| Generally, returning null when it should be an error is considered bad
| practice. (If null is a valid return value of course thats a different
| matter).
| In this case you should throw an exception and catch it in the calling
class
| and branch or throw again appropriately.
| You dont want your calling class to have to know about low level details
| like specific sql exceptions though, so instead of just letting the sql
| exception propogate upwards, you would catch it and throw a different more
| abstract exception (probably one you create yourself) up to the caller -
the
| caller shouldnt have to know the details about your persistence
mechanism -
| it just needs to know it failed - and sometimes needs to know if the
failure
| is fatal and any other pertinent info.
| The nested excpetion classes should also be able to keep a reference to
the
| exception they wrap so the stacktrace show all the exceptions in the
chain -
| useful when debugging.
|
| btw: If I recall rightly Ted Husted explains this 10 times better in one
| tenth the words in his book (struts in action)
|
| Have a look at these articles:
|
http://developer.java.sun.com/developer/technicalArticles/Programming/except
| ions/
| http://www-106.ibm.com/developerworks/java/library/j-ejb01283.html
| http://www.javaworld.com/javatips/jw-javatip91_p.html
|
| There was another very good one too - but it doesnt seem to be in my
| favourites list and I cant seem to find it now.
|
|
| -Original Message-
| From: Navjot Singh [mailto:[EMAIL PROTECTED]
| Sent: Thursday, 3 April 2003 18:53
| To: Struts Users Mailing List; [EMAIL PROTECTED]
| Subject: Re: Where to catch/throw Exceptions in Struts Tiered
| Architecture
|
|
| hi andrew,
|
| but surely these long stacktraces are not meant for users ;-)
|
| what i have got from your statement is something like this
|
| SQLException
| |__DatabaseException
| |ApplicationException
|
| finally, this ApplicationException is what is being thrown into execute()
| call.
|
| May i am novice, but I still need to be convinced about throwing so many
| exceptions in chain
|
| Can't the stuff be handled in a simple way --
| SAY
| a. when you get SQLException, catch and return NULL
| b. Calling Class __ifs__ for NULL instead of __catching__ and transfer the
| control accordingly.
|
| Is there something i am ignoring?
|
| regards
| Navjot Singh
|
| - Original Message -
| From: Andrew Hill [EMAIL PROTECTED]
| To: Struts Users Mailing List [EMAIL PROTECTED]
| Sent: Thursday, April 03, 2003 3:49 PM
| Subject: RE: Where to catch/throw Exceptions in Struts Tiered Architecture
|
|
| | I use nested exceptions, and virtually all my methods (and thus layers)
| | catch and wrap and throw...
| | Makes for some impressively long stacktraces - and is marvellous for
| | debugging! :-)
| |
| |
| | -Original Message-
| | From: Navjot Singh [mailto:[EMAIL PROTECTED]
| | Sent: Thursday, 3 April 2003 18:05
| | To: Struts Users List
| | Subject: Where to catch/throw Exceptions in Struts Tiered Architecture
| |
| |
| | Hi,
| |
| | Take a simple case.
| |
| |Action
| |   Y
| | UserAction - User - Database
| |   |
| |  V
| |   user.jsp
| |
| | Say, Database throws exception. What is best way to handle exception?
| |
| | 1. Catch in User class and return NULL / some ErrorObject to UserAction
| and
| | let UserAction decide how to handle it?
| |
| | 2. Let User class __pass on__ the Exception from Database to UserAction.
| |
| | 2a. As execute() is already throwing Exception so it will handle ALL so
| Set
| | global-exception handler that can send the user to some nice page?
| | 2b. Catch Exception in UserAction and then do some thing ...
| |
| | Which one do you guys follow in not-so-large scale web applications?
| |
| | would appreciate any comments.
| | -navjot singh
| |
| |
| |
| |
| | -
| | 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]
|
|
| -
| To unsubscribe, e-mail: [EMAIL PROTECTED]
| For additional commands, e-mail: [EMAIL PROTECTED

RE: Where to catch/throw Exceptions in Struts Tiered Architecture

2003-04-03 Thread Erica Leung
Since you guys are having a good discussion on the exceptions handling in
Struts, I would like to ask a lower level question on this topic.
On my JSP I always get a null exception something like [Exception on
\myPage.jsp: null]. At the beginning this exception was very frustrating
since no more details were showing. Now I konw in 90% of the cases, this
exception is from one of the taglibraries. But question is how I can get
more informative details without having a try/catch block on my jsps.

Regards,
Erica

-Original Message-
From: Andrew Hill [mailto:[EMAIL PROTECTED]
Sent: Thursday, April 03, 2003 3:33 AM
To: Struts Users Mailing List
Subject: RE: Where to catch/throw Exceptions in Struts Tiered
Architecture


Generally, returning null when it should be an error is considered bad
practice. (If null is a valid return value of course thats a different
matter).
In this case you should throw an exception and catch it in the calling class
and branch or throw again appropriately.
You dont want your calling class to have to know about low level details
like specific sql exceptions though, so instead of just letting the sql
exception propogate upwards, you would catch it and throw a different more
abstract exception (probably one you create yourself) up to the caller - the
caller shouldnt have to know the details about your persistence mechanism -
it just needs to know it failed - and sometimes needs to know if the failure
is fatal and any other pertinent info.
The nested excpetion classes should also be able to keep a reference to the
exception they wrap so the stacktrace show all the exceptions in the chain -
useful when debugging.

btw: If I recall rightly Ted Husted explains this 10 times better in one
tenth the words in his book (struts in action)

Have a look at these articles:
http://developer.java.sun.com/developer/technicalArticles/Programming/except
ions/
http://www-106.ibm.com/developerworks/java/library/j-ejb01283.html
http://www.javaworld.com/javatips/jw-javatip91_p.html

There was another very good one too - but it doesnt seem to be in my
favourites list and I cant seem to find it now.


-Original Message-
From: Navjot Singh [mailto:[EMAIL PROTECTED]
Sent: Thursday, 3 April 2003 18:53
To: Struts Users Mailing List; [EMAIL PROTECTED]
Subject: Re: Where to catch/throw Exceptions in Struts Tiered
Architecture


hi andrew,

but surely these long stacktraces are not meant for users ;-)

what i have got from your statement is something like this

SQLException
|__DatabaseException
|ApplicationException

finally, this ApplicationException is what is being thrown into execute()
call.

May i am novice, but I still need to be convinced about throwing so many
exceptions in chain

Can't the stuff be handled in a simple way --
SAY
a. when you get SQLException, catch and return NULL
b. Calling Class __ifs__ for NULL instead of __catching__ and transfer the
control accordingly.

Is there something i am ignoring?

regards
Navjot Singh

- Original Message -
From: Andrew Hill [EMAIL PROTECTED]
To: Struts Users Mailing List [EMAIL PROTECTED]
Sent: Thursday, April 03, 2003 3:49 PM
Subject: RE: Where to catch/throw Exceptions in Struts Tiered Architecture


| I use nested exceptions, and virtually all my methods (and thus layers)
| catch and wrap and throw...
| Makes for some impressively long stacktraces - and is marvellous for
| debugging! :-)
|
|
| -Original Message-
| From: Navjot Singh [mailto:[EMAIL PROTECTED]
| Sent: Thursday, 3 April 2003 18:05
| To: Struts Users List
| Subject: Where to catch/throw Exceptions in Struts Tiered Architecture
|
|
| Hi,
|
| Take a simple case.
|
|Action
|   Y
| UserAction - User - Database
|   |
|  V
|   user.jsp
|
| Say, Database throws exception. What is best way to handle exception?
|
| 1. Catch in User class and return NULL / some ErrorObject to UserAction
and
| let UserAction decide how to handle it?
|
| 2. Let User class __pass on__ the Exception from Database to UserAction.
|
| 2a. As execute() is already throwing Exception so it will handle ALL so
Set
| global-exception handler that can send the user to some nice page?
| 2b. Catch Exception in UserAction and then do some thing ...
|
| Which one do you guys follow in not-so-large scale web applications?
|
| would appreciate any comments.
| -navjot singh
|
|
|
|
| -
| 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]


-
To unsubscribe, e-mail: [EMAIL

RE: Where to catch/throw Exceptions in Struts Tiered Architecture

2003-04-03 Thread David Graham
I think the null is generated because the exception's message String was 
set to null.  It's helped me to print out the various scopes' attributes at 
the bottom of the page because the exceptions show up in there.

David



From: Erica Leung [EMAIL PROTECTED]
Reply-To: Struts Users Mailing List [EMAIL PROTECTED]
To: Struts Users Mailing List [EMAIL PROTECTED]
Subject: RE: Where to catch/throw Exceptions  in Struts Tiered Architecture
Date: Thu, 3 Apr 2003 11:08:56 -0800
Since you guys are having a good discussion on the exceptions handling in
Struts, I would like to ask a lower level question on this topic.
On my JSP I always get a null exception something like [Exception on
\myPage.jsp: null]. At the beginning this exception was very frustrating
since no more details were showing. Now I konw in 90% of the cases, this
exception is from one of the taglibraries. But question is how I can get
more informative details without having a try/catch block on my jsps.
Regards,
Erica
-Original Message-
From: Andrew Hill [mailto:[EMAIL PROTECTED]
Sent: Thursday, April 03, 2003 3:33 AM
To: Struts Users Mailing List
Subject: RE: Where to catch/throw Exceptions in Struts Tiered
Architecture
Generally, returning null when it should be an error is considered bad
practice. (If null is a valid return value of course thats a different
matter).
In this case you should throw an exception and catch it in the calling 
class
and branch or throw again appropriately.
You dont want your calling class to have to know about low level details
like specific sql exceptions though, so instead of just letting the sql
exception propogate upwards, you would catch it and throw a different more
abstract exception (probably one you create yourself) up to the caller - 
the
caller shouldnt have to know the details about your persistence mechanism -
it just needs to know it failed - and sometimes needs to know if the 
failure
is fatal and any other pertinent info.
The nested excpetion classes should also be able to keep a reference to the
exception they wrap so the stacktrace show all the exceptions in the chain 
-
useful when debugging.

btw: If I recall rightly Ted Husted explains this 10 times better in one
tenth the words in his book (struts in action)
Have a look at these articles:
http://developer.java.sun.com/developer/technicalArticles/Programming/except
ions/
http://www-106.ibm.com/developerworks/java/library/j-ejb01283.html
http://www.javaworld.com/javatips/jw-javatip91_p.html
There was another very good one too - but it doesnt seem to be in my
favourites list and I cant seem to find it now.
-Original Message-
From: Navjot Singh [mailto:[EMAIL PROTECTED]
Sent: Thursday, 3 April 2003 18:53
To: Struts Users Mailing List; [EMAIL PROTECTED]
Subject: Re: Where to catch/throw Exceptions in Struts Tiered
Architecture
hi andrew,

but surely these long stacktraces are not meant for users ;-)

what i have got from your statement is something like this

SQLException
|__DatabaseException
|ApplicationException
finally, this ApplicationException is what is being thrown into execute()
call.
May i am novice, but I still need to be convinced about throwing so many
exceptions in chain
Can't the stuff be handled in a simple way --
SAY
a. when you get SQLException, catch and return NULL
b. Calling Class __ifs__ for NULL instead of __catching__ and transfer the
control accordingly.
Is there something i am ignoring?

regards
Navjot Singh
- Original Message -
From: Andrew Hill [EMAIL PROTECTED]
To: Struts Users Mailing List [EMAIL PROTECTED]
Sent: Thursday, April 03, 2003 3:49 PM
Subject: RE: Where to catch/throw Exceptions in Struts Tiered Architecture
| I use nested exceptions, and virtually all my methods (and thus layers)
| catch and wrap and throw...
| Makes for some impressively long stacktraces - and is marvellous for
| debugging! :-)
|
|
| -Original Message-
| From: Navjot Singh [mailto:[EMAIL PROTECTED]
| Sent: Thursday, 3 April 2003 18:05
| To: Struts Users List
| Subject: Where to catch/throw Exceptions in Struts Tiered Architecture
|
|
| Hi,
|
| Take a simple case.
|
|Action
|   Y
| UserAction - User - Database
|   |
|  V
|   user.jsp
|
| Say, Database throws exception. What is best way to handle exception?
|
| 1. Catch in User class and return NULL / some ErrorObject to UserAction
and
| let UserAction decide how to handle it?
|
| 2. Let User class __pass on__ the Exception from Database to UserAction.
|
| 2a. As execute() is already throwing Exception so it will handle ALL so
Set
| global-exception handler that can send the user to some nice page?
| 2b. Catch Exception in UserAction and then do some thing ...
|
| Which one do you guys follow in not-so-large scale web applications?
|
| would appreciate any comments.
| -navjot singh
|
|
|
|
| -
| To unsubscribe, e-mail: [EMAIL PROTECTED]
| For additional commands, e-mail: [EMAIL

RE: Where to catch/throw Exceptions in Struts Tiered Architecture

2003-04-03 Thread Erica Leung
Is there any plug I can set up the exception's message, so I can know at
least which tag throws an exception?

-Erica

-Original Message-
From: David Graham [mailto:[EMAIL PROTECTED]
Sent: Thursday, April 03, 2003 11:21 AM
To: [EMAIL PROTECTED]
Subject: RE: Where to catch/throw Exceptions in Struts Tiered
Architecture


I think the null is generated because the exception's message String was
set to null.  It's helped me to print out the various scopes' attributes at
the bottom of the page because the exceptions show up in there.

David



From: Erica Leung [EMAIL PROTECTED]
Reply-To: Struts Users Mailing List [EMAIL PROTECTED]
To: Struts Users Mailing List [EMAIL PROTECTED]
Subject: RE: Where to catch/throw Exceptions  in Struts Tiered Architecture
Date: Thu, 3 Apr 2003 11:08:56 -0800

Since you guys are having a good discussion on the exceptions handling in
Struts, I would like to ask a lower level question on this topic.
On my JSP I always get a null exception something like [Exception on
\myPage.jsp: null]. At the beginning this exception was very frustrating
since no more details were showing. Now I konw in 90% of the cases, this
exception is from one of the taglibraries. But question is how I can get
more informative details without having a try/catch block on my jsps.

Regards,
Erica

-Original Message-
From: Andrew Hill [mailto:[EMAIL PROTECTED]
Sent: Thursday, April 03, 2003 3:33 AM
To: Struts Users Mailing List
Subject: RE: Where to catch/throw Exceptions in Struts Tiered
Architecture


Generally, returning null when it should be an error is considered bad
practice. (If null is a valid return value of course thats a different
matter).
In this case you should throw an exception and catch it in the calling
class
and branch or throw again appropriately.
You dont want your calling class to have to know about low level details
like specific sql exceptions though, so instead of just letting the sql
exception propogate upwards, you would catch it and throw a different more
abstract exception (probably one you create yourself) up to the caller -
the
caller shouldnt have to know the details about your persistence mechanism -
it just needs to know it failed - and sometimes needs to know if the
failure
is fatal and any other pertinent info.
The nested excpetion classes should also be able to keep a reference to the
exception they wrap so the stacktrace show all the exceptions in the chain
-
useful when debugging.

btw: If I recall rightly Ted Husted explains this 10 times better in one
tenth the words in his book (struts in action)

Have a look at these articles:
http://developer.java.sun.com/developer/technicalArticles/Programming/excep
t
ions/
http://www-106.ibm.com/developerworks/java/library/j-ejb01283.html
http://www.javaworld.com/javatips/jw-javatip91_p.html

There was another very good one too - but it doesnt seem to be in my
favourites list and I cant seem to find it now.


-Original Message-
From: Navjot Singh [mailto:[EMAIL PROTECTED]
Sent: Thursday, 3 April 2003 18:53
To: Struts Users Mailing List; [EMAIL PROTECTED]
Subject: Re: Where to catch/throw Exceptions in Struts Tiered
Architecture


hi andrew,

but surely these long stacktraces are not meant for users ;-)

what i have got from your statement is something like this

SQLException
|__DatabaseException
|ApplicationException

finally, this ApplicationException is what is being thrown into execute()
call.

May i am novice, but I still need to be convinced about throwing so many
exceptions in chain

Can't the stuff be handled in a simple way --
SAY
a. when you get SQLException, catch and return NULL
b. Calling Class __ifs__ for NULL instead of __catching__ and transfer the
control accordingly.

Is there something i am ignoring?

regards
Navjot Singh

- Original Message -
From: Andrew Hill [EMAIL PROTECTED]
To: Struts Users Mailing List [EMAIL PROTECTED]
Sent: Thursday, April 03, 2003 3:49 PM
Subject: RE: Where to catch/throw Exceptions in Struts Tiered Architecture


| I use nested exceptions, and virtually all my methods (and thus layers)
| catch and wrap and throw...
| Makes for some impressively long stacktraces - and is marvellous for
| debugging! :-)
|
|
| -Original Message-
| From: Navjot Singh [mailto:[EMAIL PROTECTED]
| Sent: Thursday, 3 April 2003 18:05
| To: Struts Users List
| Subject: Where to catch/throw Exceptions in Struts Tiered Architecture
|
|
| Hi,
|
| Take a simple case.
|
|Action
|   Y
| UserAction - User - Database
|   |
|  V
|   user.jsp
|
| Say, Database throws exception. What is best way to handle exception?
|
| 1. Catch in User class and return NULL / some ErrorObject to UserAction
and
| let UserAction decide how to handle it?
|
| 2. Let User class __pass on__ the Exception from Database to UserAction.
|
| 2a. As execute() is already throwing Exception so it will handle ALL so
Set
| global-exception handler that can send the user to some nice page?
| 2b. Catch

RE: Where to catch/throw Exceptions in Struts Tiered Architecture

2003-04-03 Thread David Graham
The exception message is set when the exeption object is created so you 
can't set it.  I've found it helpful to display the attributes because you 
can see the exception in there.  Other than that, it's the old fashioned 
comment-out-code-until-it-works method.

David



From: Erica Leung [EMAIL PROTECTED]
Reply-To: Struts Users Mailing List [EMAIL PROTECTED]
To: Struts Users Mailing List [EMAIL PROTECTED]
Subject: RE: Where to catch/throw Exceptions in Struts Tiered Architecture
Date: Thu, 3 Apr 2003 11:37:58 -0800
Is there any plug I can set up the exception's message, so I can know at
least which tag throws an exception?
-Erica

-Original Message-
From: David Graham [mailto:[EMAIL PROTECTED]
Sent: Thursday, April 03, 2003 11:21 AM
To: [EMAIL PROTECTED]
Subject: RE: Where to catch/throw Exceptions in Struts Tiered
Architecture
I think the null is generated because the exception's message String was
set to null.  It's helped me to print out the various scopes' attributes at
the bottom of the page because the exceptions show up in there.
David



From: Erica Leung [EMAIL PROTECTED]
Reply-To: Struts Users Mailing List [EMAIL PROTECTED]
To: Struts Users Mailing List [EMAIL PROTECTED]
Subject: RE: Where to catch/throw Exceptions  in Struts Tiered 
Architecture
Date: Thu, 3 Apr 2003 11:08:56 -0800

Since you guys are having a good discussion on the exceptions handling in
Struts, I would like to ask a lower level question on this topic.
On my JSP I always get a null exception something like [Exception on
\myPage.jsp: null]. At the beginning this exception was very frustrating
since no more details were showing. Now I konw in 90% of the cases, this
exception is from one of the taglibraries. But question is how I can get
more informative details without having a try/catch block on my jsps.

Regards,
Erica

-Original Message-
From: Andrew Hill [mailto:[EMAIL PROTECTED]
Sent: Thursday, April 03, 2003 3:33 AM
To: Struts Users Mailing List
Subject: RE: Where to catch/throw Exceptions in Struts Tiered
Architecture


Generally, returning null when it should be an error is considered bad
practice. (If null is a valid return value of course thats a different
matter).
In this case you should throw an exception and catch it in the calling
class
and branch or throw again appropriately.
You dont want your calling class to have to know about low level details
like specific sql exceptions though, so instead of just letting the sql
exception propogate upwards, you would catch it and throw a different 
more
abstract exception (probably one you create yourself) up to the caller -
the
caller shouldnt have to know the details about your persistence mechanism 
-
it just needs to know it failed - and sometimes needs to know if the
failure
is fatal and any other pertinent info.
The nested excpetion classes should also be able to keep a reference to 
the
exception they wrap so the stacktrace show all the exceptions in the 
chain
-
useful when debugging.

btw: If I recall rightly Ted Husted explains this 10 times better in one
tenth the words in his book (struts in action)

Have a look at these articles:
http://developer.java.sun.com/developer/technicalArticles/Programming/excep
t
ions/
http://www-106.ibm.com/developerworks/java/library/j-ejb01283.html
http://www.javaworld.com/javatips/jw-javatip91_p.html

There was another very good one too - but it doesnt seem to be in my
favourites list and I cant seem to find it now.


-Original Message-
From: Navjot Singh [mailto:[EMAIL PROTECTED]
Sent: Thursday, 3 April 2003 18:53
To: Struts Users Mailing List; [EMAIL PROTECTED]
Subject: Re: Where to catch/throw Exceptions in Struts Tiered
Architecture


hi andrew,

but surely these long stacktraces are not meant for users ;-)

what i have got from your statement is something like this

SQLException
|__DatabaseException
|ApplicationException

finally, this ApplicationException is what is being thrown into execute()
call.

May i am novice, but I still need to be convinced about throwing so many
exceptions in chain

Can't the stuff be handled in a simple way --
SAY
a. when you get SQLException, catch and return NULL
b. Calling Class __ifs__ for NULL instead of __catching__ and transfer 
the
control accordingly.

Is there something i am ignoring?

regards
Navjot Singh

- Original Message -
From: Andrew Hill [EMAIL PROTECTED]
To: Struts Users Mailing List [EMAIL PROTECTED]
Sent: Thursday, April 03, 2003 3:49 PM
Subject: RE: Where to catch/throw Exceptions in Struts Tiered 
Architecture


| I use nested exceptions, and virtually all my methods (and thus layers)
| catch and wrap and throw...
| Makes for some impressively long stacktraces - and is marvellous for
| debugging! :-)
|
|
| -Original Message-
| From: Navjot Singh [mailto:[EMAIL PROTECTED]
| Sent: Thursday, 3 April 2003 18:05
| To: Struts Users List
| Subject: Where to catch/throw Exceptions in Struts Tiered Architecture
|
|
| Hi,
|
| Take a simple