You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Slimane Zouggari <sl...@clin.ucl.ac.be> on 2002/03/21 09:51:51 UTC

How to handle exceptions properly ?

Hi,

I already looked at the JGuru FAQ and other resources but I didn't find any 
good (and complete information) on the subject. So, if it's already been 
asked, I'm very sorry and I hope you would point me to the URL where I can 
find the info.

So, what's the best way to handle exceptions properly when they occur in 
the Action classes ?

Here's what I do for now:
	I just catch them, and then I return a mapping to an error page (a static 
html page)

Here's how I think I will improve the process:
	Store the exception message in a session attribute. Then, I'll still do 
the mapping to an error page. And in that error page, I'll retrieve the 
exception message (which will be stored in a session attribute as 
previuously said)

Is it a good method ?
Is there a better method, knowing it's an intranet site. So it won't be 
seen by other persons (except those of my company of course :)

Friendly Regards,
Slimane


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: How to handle exceptions properly ?

Posted by hemant <xr...@yahoo.com>.
----- Original Message -----
From: "Slimane Zouggari" <sl...@clin.ucl.ac.be>
To: <st...@jakarta.apache.org>
Sent: Thursday, March 21, 2002 3:51 AM
Subject: How to handle exceptions properly ?


> Hi,
>
> I already looked at the JGuru FAQ and other resources but I didn't find
any
> good (and complete information) on the subject. So, if it's already been
> asked, I'm very sorry and I hope you would point me to the URL where I can
> find the info.
>

Here is a decent link to info on how you can create your own customized
exceptions in the DAO/EJB layer. Since EJB's are Fuction specific, it would
make sense to catch multiple exceptions from the layers below, Log them and
consolidate them into a customized exception which arecaught in Action
classes.
http://www.javaworld.com/jw-08-2000/jw-0818-exceptions-p2.html




> So, what's the best way to handle exceptions properly when they occur in
> the Action classes ?

--------> I guess we can proceed in more than a couple of ways

1.Struts Action class provides a method  saveErrors(HttpServletRequest
request,  ActionErrors errors) to pass the errorr messages to the struts
error tag.

When an exception occurs we can create an error in the catch block as shown
below and call saveErrors(request, errors) in the perform method.

try
            {

            uvo = udao.getUser(userId, pwd);
        }
        catch (DaoException daoe)
            {
            errors.add(
                ActionErrors.GLOBAL_ERROR,   new ActionError("Error Logging
in"));
        }


2.Catch exceptions in your actions and redirect the user to an error page as
you mentioned, since the errors are not session specific, you can maintain a
repository of messages (more likey a db) and/or  save them in the servlet
context?



> Here's what I do for now:
> I just catch them, and then I return a mapping to an error page (a static
> html page)
>
> Here's how I think I will improve the process:
> Store the exception message in a session attribute. Then, I'll still do
> the mapping to an error page. And in that error page, I'll retrieve the
> exception message (which will be stored in a session attribute as
> previuously said)
>
> Is it a good method ?
> Is there a better method, knowing it's an intranet site. So it won't be
> seen by other persons (except those of my company of course :)
>
> Friendly Regards,
> Slimane
>
>
> --
> To unsubscribe, e-mail:
<ma...@jakarta.apache.org>
> For additional commands, e-mail:
<ma...@jakarta.apache.org>


_________________________________________________________
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>