Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Exception Handling  RSS feed

 
Hari babu
Ranch Hand
Posts: 208
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Here's what we follow in handling exceptions in our design. I want your comments on the same and want to know any other better approaches.
We throw Application exception (extends java.lang.Exception) from the EJB layer, only in the case where we want to show some error message to the end user. So that he/she can change the entered data and proceed.We catch the application exception in weblayer and display the error message back to the end user.
System exception (extends java.lang.RunTimeException) is thrown from the EJB layer for any error related to the configuration. For example if EJB A is looking for EJB B, in the method of EJB A where we lookup for EJB B, we catch "namingException" (thrown by the lookup() method of the InitialContext) and throw a SystemException, because throwing "naming exception" back to the presentation layer doesnt make any sense to the end user since the exception has occured due to the EJB developer/deployer mistake. The System exceptions are not caught by the presentation layer but configured in the web.xml to redirect the user to a common error page.
[ May 27, 2003: Message edited by: Hari babu ]
 
Karthik Guru
Ranch Hand
Posts: 1209
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Hari babu:
Hi,
We throw Application exception (extends java.lang.Exception) from the EJB layer, only in the case where we want to show some error message to the end user. So that he/she can change the entered data and proceed.We catch the application exception in weblayer and display the error message back to the end user.
May 27, 2003: Message edited by: Hari babu ]

Throwing application exceptions does'nt result in automatic rollback.
If you are lookign for rollback, try doing a
ejbContext.setRollBackOnly() before throwing the exception. This s'd mark the transaction for rollback. It might help you in case there were partial updates to the DB.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!