Jump to content


Struts ExceptionHandler


  • You cannot reply to this topic
No replies to this topic

#1 abhishek

    Young Padawan

  • Members
  • Pip
  • 2 posts

Posted 05 January 2005 - 08:10 AM

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,
Abhishek





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users