You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Quaini Michele <mi...@fastweb.it> on 2000/07/19 17:51:05 UTC

SQLException

Hello to the list



in an Action bean my perform method calls some business beans 
that works on the database and can raise a SQLException.

Now, the perform method of the ActionBase throws the exceptions

IOException, ServletException

What is the suggested method:

to add the throwing of a SQLException to the perform method
or to catch at a lower level the SQLexception and return a "failure" code?

thanks,

michele


Re: SQLException

Posted by "Craig R. McClanahan" <Cr...@eng.sun.com>.
Quaini Michele wrote:

> Hello to the list
>
> in an Action bean my perform method calls some business beans
> that works on the database and can raise a SQLException.
>
> Now, the perform method of the ActionBase throws the exceptions
>
> IOException, ServletException
>
> What is the suggested method:
>
> to add the throwing of a SQLException to the perform method
> or to catch at a lower level the SQLexception and return a "failure" code?
>

My personal design philosophy is to *never* have my action class (or a servlet
or JSP page, for that matter) throw an exception that has to be trapped by the
servlet container if I can help it.  The reason for this is that such errors
almost always result in a really ugly error traceback screen being sent back
to the user, who has no clue what happened or what to do now.

Therefore, I suggest you always trap things like SQLException and translate
them into some human understandable error condition, which might mean
forwarding to a page that just says "I'm sorry, but something unexpected
happened so I cannot fulfill your request.".  (But don't forget to log all the
details in a log file, so that *you* can go figure out what happened --
calling servlet.log(String message, Throwable exception) is useful for this.)


>
> thanks,
>
> michele

Craig McClanahan