Re: Help with using declarative error handling

2004-05-18 Thread Frank Burns
Joe,
You be da man!
Thanks.
Frank

- Original Message - 
From: "Joe Germuska" <[EMAIL PROTECTED]>
To: "Struts Users Mailing List" <[EMAIL PROTECTED]>
Sent: Tuesday, May 18, 2004 1:56 PM
Subject: Re: Help with using declarative error handling


> At 1:58 AM +0100 5/18/04, Frank Burns wrote:
> >
> >This seems simple enough. So why doesn't it work?
>
> Because the default ExceptionHandler class saves its own error
> messages into the request under the same key that Action.saveErrors()
> uses, overwriting the reference to the errors that you saved.
>
>
http://jakarta.apache.org/struts/api/org/apache/struts/action/ExceptionHandler.html#storeException(javax.servlet.http.HttpServletRequest,%20java.lang.String,%20org.apache.struts.action.ActionError,%20org.apache.struts.action.ActionForward,%20java.lang.String)
>
>
>
>
> >Hi Wendy,
> >
> >Thanks for your reply. I know that what you suggest is a solution.
> >
> >But I don't understand why what I originally tried doesn't work, which is
to
> >add some code in the catch block, before rethrowing it, for example like
> >this:
> >
> >   } catch(TrcDatabaseException ex){
> >/* add relevant action errors */
> >ActionErrors errors = new ActionErrors();
> >errors.add(ActionErors.GLOBAL_ERROR, new
> >ActionError("errors.database.noconnection"));
> >saveErrors(request, errors);
> >/* rethrow the exception to be caught by Struts declarative exception
> >handling mechanism */
> >throw ex;
> >   }
> >
> >and have  display it in the JSP that is forwarded to.
>
> -- 
> Joe Germuska
> [EMAIL PROTECTED]
> http://blog.germuska.com
>"Imagine if every Thursday your shoes exploded if you tied them
> the usual way.  This happens to us all the time with computers, and
> nobody thinks of complaining."
>  -- Jef Raskin
>
> -
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: Help with using declarative error handling

2004-05-18 Thread Joe Germuska
At 1:58 AM +0100 5/18/04, Frank Burns wrote:
This seems simple enough. So why doesn't it work?
Because the default ExceptionHandler class saves its own error 
messages into the request under the same key that Action.saveErrors() 
uses, overwriting the reference to the errors that you saved.

http://jakarta.apache.org/struts/api/org/apache/struts/action/ExceptionHandler.html#storeException(javax.servlet.http.HttpServletRequest,%20java.lang.String,%20org.apache.struts.action.ActionError,%20org.apache.struts.action.ActionForward,%20java.lang.String)


Hi Wendy,
Thanks for your reply. I know that what you suggest is a solution.
But I don't understand why what I originally tried doesn't work, which is to
add some code in the catch block, before rethrowing it, for example like
this:
  } catch(TrcDatabaseException ex){
   /* add relevant action errors */
   ActionErrors errors = new ActionErrors();
   errors.add(ActionErors.GLOBAL_ERROR, new
ActionError("errors.database.noconnection"));
   saveErrors(request, errors);
   /* rethrow the exception to be caught by Struts declarative exception
handling mechanism */
   throw ex;
  }
and have  display it in the JSP that is forwarded to.
--
Joe Germuska
[EMAIL PROTECTED]  
http://blog.germuska.com
  "Imagine if every Thursday your shoes exploded if you tied them 
the usual way.  This happens to us all the time with computers, and 
nobody thinks of complaining."
-- Jef Raskin

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


RE: Help with using declarative error handling

2004-05-17 Thread Patrick Cheng
Hi,
What we do in our project is, we have a top level exception class, say,
RootException(), which does nothing.
Then you keep all your try catch, if you do whatever you want in the
catch block, but at the end, you re 

 ' throw new RootException("with your description in it") '
Now your global exception handler will handle the RootException with
details in it. 
Don't know if it helps, but that's what we do.

Rgds.
Pat

-Original Message-
From: Frank Burns [mailto:[EMAIL PROTECTED] 
Sent: Tuesday, May 18, 2004 5:29 AM
To: [EMAIL PROTECTED]
Subject: Re: Help with using declarative error handling


Thanks for your reply, Bill.

I already appreciate the point you are making,

However, the problem I am trying to solve is that my AuthenticateAction
class can throw the TRCDatabaseException in SEVERAL places.

The example you provide will display the same error message for ALL
TRCDatabaseExceptions that occur in my Action class.

I want to be able to display a DIFFERENT error message for each place in
the code where the exception can occur.

Hence my attempted solution -- which doesn't work.

Any ideas?

Thanks,

Frank.

- Original Message - 
From: "Bill Schneider" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Monday, May 17, 2004 1:18 PM
Subject: Re: Help with using declarative error handling


> Hi,
>
> try changing the exception handler in struts-config.xml to
>
> key="errors.database.noconnection"
>type="mydomain.exception.TrcDatabaseException"
>path="/common/exceptionTrcDatabase.jsp"
>/>
>
> You can get rid of the whole catch block in your action--the 
> ActionServlet takes care of it.  That's the beauty of declarative 
> exceptions.
>
> -- Bill
>
>
>   >> Wherever an exception is thrown in AuthenticateAction, I add some

> code in
>   >> the catch block, before rethrowing it, for example like this:
>   >>
>   >>   } catch(TrcDatabaseException ex){
>   >>/* add relevant action errors */
>   >>ActionErrors errors = new ActionErrors();
>   >>errors.add(ActionErors.GLOBAL_ERROR, new
>   >> ActionError("errors.database.noconnection"));
>   >>saveErrors(request, errors);
>   >>/* rethrow the exception to be caught by Struts declarative
> exception
>   >> handling mechanism */
>   >>throw ex;
>   >>   }
>   >>
>   >> I have also placed an errors.database.noconnection in the 
> resource file.
>   >>
>   >> In the struts-config file, for the AuthenticateAction, I have 
> defined an
>   >> exception element:
>   >>
>   >>>> key="errors.generalmessage"
>   >> type="mydomain.exception.TrcDatabaseException"
>   >> path="/common/exceptionTrcDatabase.jsp"
>   >> />
>   >>
>   >> I have created a JSP, exceptionTrcDatabase.jsp, that contains 
> this
> element:
>   >>
>   >> 
>   >>
>   >> However, whenever I test this code (by deliberately creating the
> relevant
>   >> error conditions), only the errors.generalmessage is displayed.
>   >>
>   >> Why isn't the errors.database.noconnection being displayed as
well?
>
> -- Bill Schneider Chief Architect Vecna Technologies, Inc. 5004 Lehigh

> Road, Suite B College Park, MD 20740 [EMAIL PROTECTED] t: 
> 301-864-7594 f: 301-699-3180
> --
> Bill Schneider
> Chief Architect
>
> Vecna Technologies, Inc.
> 5004 Lehigh Road, Suite B
> College Park, MD 20740
> [EMAIL PROTECTED]
> t: 301-864-7594
> f: 301-699-3180
>
>
> -
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: Help with using declarative error handling

2004-05-17 Thread Frank Burns
Hi Wendy,

Thanks for your reply. I know that what you suggest is a solution.

But I don't understand why what I originally tried doesn't work, which is to
add some code in the catch block, before rethrowing it, for example like
this:

  } catch(TrcDatabaseException ex){
   /* add relevant action errors */
   ActionErrors errors = new ActionErrors();
   errors.add(ActionErors.GLOBAL_ERROR, new
ActionError("errors.database.noconnection"));
   saveErrors(request, errors);
   /* rethrow the exception to be caught by Struts declarative exception
handling mechanism */
   throw ex;
  }

and have  display it in the JSP that is forwarded to.

This seems simple enough. So why doesn't it work?

Any ideas why it doesn't?

Cheers,

Frank

- Original Message - 
From: "Wendy Smoak" <[EMAIL PROTECTED]>
To: "Struts Users Mailing List" <[EMAIL PROTECTED]>
Sent: Tuesday, May 18, 2004 12:01 AM
Subject: RE: Help with using declarative error handling


> From: Frank Burns [mailto:[EMAIL PROTECTED]
> However, the problem I am trying to solve is that my
> AuthenticateAction
> class can throw the TRCDatabaseException in SEVERAL places.
>
> I want to be able to display a DIFFERENT error message for
> each place in the
> code where the exception can occur.

What about subclassing TRCDatabaseException and making different
exceptions for the different bad things that can happen?

For example, I have a generic "DAOException", and beneath that,
RecordNotFoundException, RecordLockedException, etc.

Then throw the exception that describes what really happened, and let
Struts do its thing.

-- 
Wendy Smoak
Application Systems Analyst, Sr.
ASU IA Information Resources Management

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Hi,

I can't get the relevant error message from the resources file to display
when an exception is thrown.

Can you please help? Here is the scenario:

One of my Action classes, AuthenticateAction, can generate the same type of
application-specific exception (TrcDatabaseException) at various points in
its code.

I want to display error-specific information for each place where the
TrcDatabaseException can be thrown in the AuthenticateAction.

Wherever an exception is thrown in AuthenticateAction, I add some code in
the catch block, before rethrowing it, for example like this:

  } catch(TrcDatabaseException ex){
   /* add relevant action errors */
   ActionErrors errors = new ActionErrors();
   errors.add(ActionErors.GLOBAL_ERROR, new
ActionError("errors.database.noconnection"));
   saveErrors(request, errors);
   /* rethrow the exception to be caught by Struts declarative exception
handling mechanism */
   throw ex;
  }

I have also placed an errors.database.noconnection in the resource file.

In the struts-config file, for the AuthenticateAction, I have defined an
exception element:



I have created a JSP, exceptionTrcDatabase.jsp, that contains this element:



However, whenever I test this code (by deliberately creating the relevant
error conditions), only the errors.generalmessage is displayed.

Why isn't the errors.database.noconnection being displayed as well?

Thanks,

Frank.


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



RE: Help with using declarative error handling

2004-05-17 Thread Wendy Smoak
> From: Frank Burns [mailto:[EMAIL PROTECTED] 
> However, the problem I am trying to solve is that my 
> AuthenticateAction
> class can throw the TRCDatabaseException in SEVERAL places.
> 
> I want to be able to display a DIFFERENT error message for 
> each place in the
> code where the exception can occur.

What about subclassing TRCDatabaseException and making different
exceptions for the different bad things that can happen?

For example, I have a generic "DAOException", and beneath that,
RecordNotFoundException, RecordLockedException, etc.

Then throw the exception that describes what really happened, and let
Struts do its thing.

-- 
Wendy Smoak
Application Systems Analyst, Sr.
ASU IA Information Resources Management 

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: Help with using declarative error handling

2004-05-17 Thread Frank Burns
Thanks for your reply, Bill.

I already appreciate the point you are making,

However, the problem I am trying to solve is that my AuthenticateAction
class can throw the TRCDatabaseException in SEVERAL places.

The example you provide will display the same error message for ALL
TRCDatabaseExceptions that occur in my Action class.

I want to be able to display a DIFFERENT error message for each place in the
code where the exception can occur.

Hence my attempted solution -- which doesn't work.

Any ideas?

Thanks,

Frank.

- Original Message - 
From: "Bill Schneider" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Monday, May 17, 2004 1:18 PM
Subject: Re: Help with using declarative error handling


> Hi,
>
> try changing the exception handler in struts-config.xml to
>
> key="errors.database.noconnection"
>type="mydomain.exception.TrcDatabaseException"
>path="/common/exceptionTrcDatabase.jsp"
>/>
>
> You can get rid of the whole catch block in your action--the
> ActionServlet takes care of it.  That's the beauty of declarative
> exceptions.
>
> -- Bill
>
>
>   >> Wherever an exception is thrown in AuthenticateAction, I add some
> code in
>   >> the catch block, before rethrowing it, for example like this:
>   >>
>   >>   } catch(TrcDatabaseException ex){
>   >>/* add relevant action errors */
>   >>ActionErrors errors = new ActionErrors();
>   >>errors.add(ActionErors.GLOBAL_ERROR, new
>   >> ActionError("errors.database.noconnection"));
>   >>saveErrors(request, errors);
>   >>/* rethrow the exception to be caught by Struts declarative
> exception
>   >> handling mechanism */
>   >>throw ex;
>   >>   }
>   >>
>   >> I have also placed an errors.database.noconnection in the resource
> file.
>   >>
>   >> In the struts-config file, for the AuthenticateAction, I have
> defined an
>   >> exception element:
>   >>
>   >>>> key="errors.generalmessage"
>   >> type="mydomain.exception.TrcDatabaseException"
>   >> path="/common/exceptionTrcDatabase.jsp"
>   >> />
>   >>
>   >> I have created a JSP, exceptionTrcDatabase.jsp, that contains this
> element:
>   >>
>   >> 
>   >>
>   >> However, whenever I test this code (by deliberately creating the
> relevant
>   >> error conditions), only the errors.generalmessage is displayed.
>   >>
>   >> Why isn't the errors.database.noconnection being displayed as well?
>
> -- Bill Schneider Chief Architect Vecna Technologies, Inc. 5004 Lehigh
> Road, Suite B College Park, MD 20740 [EMAIL PROTECTED] t:
> 301-864-7594 f: 301-699-3180
> -- 
> Bill Schneider
> Chief Architect
>
> Vecna Technologies, Inc.
> 5004 Lehigh Road, Suite B
> College Park, MD 20740
> [EMAIL PROTECTED]
> t: 301-864-7594
> f: 301-699-3180
>
>
> -
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: Help with using declarative error handling

2004-05-17 Thread Bill Schneider
Hi,
try changing the exception handler in struts-config.xml to

You can get rid of the whole catch block in your action--the
ActionServlet takes care of it.  That's the beauty of declarative
exceptions.
-- Bill
 >> Wherever an exception is thrown in AuthenticateAction, I add some
code in
 >> the catch block, before rethrowing it, for example like this:
 >>
 >>   } catch(TrcDatabaseException ex){
 >>/* add relevant action errors */
 >>ActionErrors errors = new ActionErrors();
 >>errors.add(ActionErors.GLOBAL_ERROR, new
 >> ActionError("errors.database.noconnection"));
 >>saveErrors(request, errors);
 >>/* rethrow the exception to be caught by Struts declarative 
exception
 >> handling mechanism */
 >>throw ex;
 >>   }
 >>
 >> I have also placed an errors.database.noconnection in the resource 
file.
 >>
 >> In the struts-config file, for the AuthenticateAction, I have 
defined an
 >> exception element:
 >>
 >> 
 >> key="errors.generalmessage"
 >> type="mydomain.exception.TrcDatabaseException"
 >> path="/common/exceptionTrcDatabase.jsp"
 >> />
 >>
 >> I have created a JSP, exceptionTrcDatabase.jsp, that contains this
element:
 >>
 >> 
 >>
 >> However, whenever I test this code (by deliberately creating the
relevant
 >> error conditions), only the errors.generalmessage is displayed.
 >>
 >> Why isn't the errors.database.noconnection being displayed as well?

-- Bill Schneider Chief Architect Vecna Technologies, Inc. 5004 Lehigh 
Road, Suite B College Park, MD 20740 [EMAIL PROTECTED] t: 
301-864-7594 f: 301-699-3180
--
Bill Schneider
Chief Architect

Vecna Technologies, Inc.
5004 Lehigh Road, Suite B
College Park, MD 20740
[EMAIL PROTECTED]
t: 301-864-7594
f: 301-699-3180
-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]