I'm trying to find out how to properly handle Exceptions.
For example if entity bean throws SQL exception because there is missing value for non nullable column I want to show in JSP errorPage original database error text. Unfortunally it will be something else.
Is it feasible to catch first exception in session facade, extract error message, and instead of re-throwing Exception put message in HashMap and return it to client.
Client would check if exception exists in HashMap and display it to user. If there is no Exception I would put the value(s) in HashMap and client would use it.
====================================================
public class MySessionBean implements SessionBean{
...
public HashMap myMethod(){
HashMap retValue = new HashMap();
String someValue;
...
try{
MyEntityBean myEntityBean = ...;
someValue = myEntityBean.doSomething();
}catch (Exception e){
retValue.put("Exception", e.getMessage());
return retValue;
}
retValue.put("someValue", someValue);
return retValue;
}
}
=======================================================
Is it good/bad solution?
TIA
-
How to properly handle Exceptions? (4 messages)
- Posted by: Leonard Gurevich
- Posted on: September 06 2002 14:33 EDT
Threaded Messages (4)
- How to properly handle Exceptions? by hoi tsang on September 06 2002 15:27 EDT
- How to properly handle Exceptions? by Sean Sullivan on September 06 2002 23:16 EDT
- How to properly handle Exceptions? by Upendra Kota on September 07 2002 00:40 EDT
- How to properly handle Exceptions? by Robert Simmons on September 07 2002 11:48 EDT
-
How to properly handle Exceptions?[ Go to top ]
- Posted by: hoi tsang
- Posted on: September 06 2002 15:27 EDT
- in response to Leonard Gurevich
Best practices in EJB exception handling:
http://www-106.ibm.com/developerworks/library/j-ejbexcept.html
-
How to properly handle Exceptions?[ Go to top ]
- Posted by: Sean Sullivan
- Posted on: September 06 2002 23:16 EDT
- in response to Leonard Gurevich
Josh Bloch's book "Effective Java" has some wonderful exception handling advice.
-
How to properly handle Exceptions?[ Go to top ]
- Posted by: Upendra Kota
- Posted on: September 07 2002 00:40 EDT
- in response to Leonard Gurevich
As far as i know its not good to display original exception. Here having keep in mind the end user, proper message should be passed. so better use user defined exceptions. First catch the original sql exception according to that rethrow the user defined exception..catch it in the client and display the exception description to the end user.
thanking you -
How to properly handle Exceptions?[ Go to top ]
- Posted by: Robert Simmons
- Posted on: September 07 2002 11:48 EDT
- in response to Upendra Kota
SQL exceptions should not happen at all. YOur application should guard against them. If they do happen, you are better off displaying some kind of error to the user that tells them the issue has been logged and then to use Log4J to sned the log of the error to a JMS source which will can then be routed to the appropriate recipient.