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
Struts ExceptionHandler
Started by abhishek, Jan 05 2005 08:10 AM
No replies to this topic
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users
