You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Michael Davis <mi...@damaru.com> on 2006/02/02 18:49:49 UTC
global exception handler sometimes gets a null exception
Hello,
I'm working on a struts application which has just been deployed and is
being used by a large number of users. I've got an error handler set up
using the global-exceptions tag. It sends me an email whenever it
catches an exception.
My config looks like this:
<global-exceptions>
<exception type="java.lang.Throwable"
key="error.error"
path="/err100.do"/>
</global-exceptions>
And my code does this:
Throwable e = (Throwable) request.getAttribute( Globals.EXCEPTION_KEY );
(remember that Globals.EXCEPTION_KEY is
"org.apache.struts.action.EXCEPTION").
Now my problem is that about half the time, e is null, so I can't
determine where the exception happened or even what it is.
Somehow struts is able to invoke my error handler, but sometimes does it
without setting Globals.EXCEPTION_KEY in the request. When does that
happen? How can I figure out what caused the error to happen?
thanks very much,
Michael from Ottawa
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: global exception handler sometimes gets a null exception
Posted by Vladislav Pernin <vl...@openwide.fr>.
Maybe it happens when the error is not thrown by Struts, so try to use
the JSP directive <%@ page isErrorPage="true" %> which give you access
to the implicit variable exception.
You can also use a exception handler :
<exception type="java.lang.Throwable"
key="error.error"
path="/err100.do"
handler="com.ddd.GlobalExceptionHandler"/>
package com.ddd;
public class GlobalExceptionHandler extends ExceptionHandler {
public ActionForward execute(Exception ex,
ExceptionConfig exConfig,
ActionMapping mapping,
ActionForm formInstance,
HttpServletRequest request,
HttpServletResponse response) throws ServletException {
/* your custom code */
return super.execute(ex, exConfig, mapping, formInstance,
request, response);
}
Vlad
Michael Davis wrote:
>Hello,
>
>I'm working on a struts application which has just been deployed and is
>being used by a large number of users. I've got an error handler set up
>using the global-exceptions tag. It sends me an email whenever it
>catches an exception.
>
>My config looks like this:
>
> <global-exceptions>
> <exception type="java.lang.Throwable"
> key="error.error"
> path="/err100.do"/>
> </global-exceptions>
>
>And my code does this:
>
>Throwable e = (Throwable) request.getAttribute( Globals.EXCEPTION_KEY );
>
>(remember that Globals.EXCEPTION_KEY is
>"org.apache.struts.action.EXCEPTION").
>
>Now my problem is that about half the time, e is null, so I can't
>determine where the exception happened or even what it is.
>
>Somehow struts is able to invoke my error handler, but sometimes does it
>without setting Globals.EXCEPTION_KEY in the request. When does that
>happen? How can I figure out what caused the error to happen?
>
>thanks very much,
>Michael from Ottawa
>
>
>
>
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>For additional commands, e-mail: user-help@struts.apache.org
>
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: global exception handler sometimes gets a null exception
Posted by Michael Davis <mi...@damaru.com>.
Thanks for your prompt replies!
I will try supplying my own exception handler. Looking at the struts
source code for the exception handler, I see:
// Figure out the error
if (ex instanceof ModuleException) {
error = ((ModuleException) ex).getActionMessage();
property = ((ModuleException) ex).getProperty();
} else {
error = new ActionMessage(ae.getKey(), ex.getMessage());
property = error.getKey();
}
This would cause a null pointer exception if ex were null, and I'm not
sure what struts would do in that case, (i.e. who catches it if this
method throws?) but now I can at least see if this method is getting a
null exception.
cheers
--
Michael Davis
http://www.damaru.com
Quoting Mark Shifman <ma...@yale.edu>:
> What I do is log the exception and the stack trace and then let the
> super do the rest.
> Since I was getting null comming up on the error page, I check the
> exception message and if it is null
> I at least show the name of the exception class name on the error
> page
> (probably not too pretty but..)
>
> The log with the stack trace should give you all the stuff you are
> looking for.
> mas
>
>
> public class YPEDExceptionHandler extends ExceptionHandler {
> private static final Log log =
> LogFactory.getLog(YPEDExceptionHandler.class);
>
> public ActionForward execute(Exception ex, ExceptionConfig ae,
> ActionMapping mapping, ActionForm formInstance,
> HttpServletRequest request, HttpServletResponse
> response)
> throws ServletException {
> //log the user and the stack trace then pass on to the default
> exceptionHandler
> HttpSession session = request.getSession();
> MySessionCleanerBean user_bean = (MySessionCleanerBean)
> session.getAttribute("user_bean");
> if(user_bean != null){
> log.fatal("user: "+ user_bean.getUser_name() + " logon_id:
> "+
> user_bean.getLogon_id(),ex);
> }else {
> log.fatal("no user_bean in session", ex);
> }
> if(ex.getMessage() == null){
> return super.execute(new
> YPEDException(ex.getClass().getName(),ex), ae, mapping, formInstance,
>
> request, response);
> }
>
> return super.execute(ex, ae, mapping, formInstance, request,
>
> response);
> }
>
>
> Michael Davis wrote:
>
> >Hello,
> >
> >I'm working on a struts application which has just been deployed and
> is
> >being used by a large number of users. I've got an error handler set
> up
> >using the global-exceptions tag. It sends me an email whenever it
> >catches an exception.
> >
> >My config looks like this:
> >
> > <global-exceptions>
> > <exception type="java.lang.Throwable"
> > key="error.error"
> > path="/err100.do"/>
> > </global-exceptions>
> >
> >And my code does this:
> >
> >Throwable e = (Throwable) request.getAttribute(
> Globals.EXCEPTION_KEY );
> >
> >(remember that Globals.EXCEPTION_KEY is
> >"org.apache.struts.action.EXCEPTION").
> >
> >Now my problem is that about half the time, e is null, so I can't
> >determine where the exception happened or even what it is.
> >
> >Somehow struts is able to invoke my error handler, but sometimes
> does it
> >without setting Globals.EXCEPTION_KEY in the request. When does
> that
> >happen? How can I figure out what caused the error to happen?
> >
> >thanks very much,
> >Michael from Ottawa
> >
> >
> >
> >
> >
> >
> >---------------------------------------------------------------------
> >To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> >For additional commands, e-mail: user-help@struts.apache.org
> >
> >
> >
>
>
> --
> Mark Shifman MD. Ph.D.
> Yale Center for Medical Informatics
> Phone (203)737-5219
> mark.shifman@yale.edu
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: global exception handler sometimes gets a null exception
Posted by Mark Shifman <ma...@yale.edu>.
What I do is log the exception and the stack trace and then let the
super do the rest.
Since I was getting null comming up on the error page, I check the
exception message and if it is null
I at least show the name of the exception class name on the error page
(probably not too pretty but..)
The log with the stack trace should give you all the stuff you are
looking for.
mas
public class YPEDExceptionHandler extends ExceptionHandler {
private static final Log log =
LogFactory.getLog(YPEDExceptionHandler.class);
public ActionForward execute(Exception ex, ExceptionConfig ae,
ActionMapping mapping, ActionForm formInstance,
HttpServletRequest request, HttpServletResponse response)
throws ServletException {
//log the user and the stack trace then pass on to the default
exceptionHandler
HttpSession session = request.getSession();
MySessionCleanerBean user_bean = (MySessionCleanerBean)
session.getAttribute("user_bean");
if(user_bean != null){
log.fatal("user: "+ user_bean.getUser_name() + " logon_id: "+
user_bean.getLogon_id(),ex);
}else {
log.fatal("no user_bean in session", ex);
}
if(ex.getMessage() == null){
return super.execute(new
YPEDException(ex.getClass().getName(),ex), ae, mapping, formInstance,
request, response);
}
return super.execute(ex, ae, mapping, formInstance, request,
response);
}
Michael Davis wrote:
>Hello,
>
>I'm working on a struts application which has just been deployed and is
>being used by a large number of users. I've got an error handler set up
>using the global-exceptions tag. It sends me an email whenever it
>catches an exception.
>
>My config looks like this:
>
> <global-exceptions>
> <exception type="java.lang.Throwable"
> key="error.error"
> path="/err100.do"/>
> </global-exceptions>
>
>And my code does this:
>
>Throwable e = (Throwable) request.getAttribute( Globals.EXCEPTION_KEY );
>
>(remember that Globals.EXCEPTION_KEY is
>"org.apache.struts.action.EXCEPTION").
>
>Now my problem is that about half the time, e is null, so I can't
>determine where the exception happened or even what it is.
>
>Somehow struts is able to invoke my error handler, but sometimes does it
>without setting Globals.EXCEPTION_KEY in the request. When does that
>happen? How can I figure out what caused the error to happen?
>
>thanks very much,
>Michael from Ottawa
>
>
>
>
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>For additional commands, e-mail: user-help@struts.apache.org
>
>
>
--
Mark Shifman MD. Ph.D.
Yale Center for Medical Informatics
Phone (203)737-5219
mark.shifman@yale.edu
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: global exception handler sometimes gets a null exception
Posted by "Frank W. Zammetti" <fz...@omnytex.com>.
With the caveat that I looked at things for all of 30 seconds so I could
be WAY wrong...
Looking at the Struts source, the RequestProcessor.processException()
method is where your custom handler gets called from. I notice that the
request attribute is NOT set there. In fact, there is no reference to
EXCEPTION_KEY in the RP. So, where is it set?
Looks to me like it gets set in the ExceptionHandler.execute() method.
But, since you will extend this class to create your own handler and
override execute(), you have to, unless I'm missing something, set the
request attribute yourself.
So, my theory is that the half of the time the type of exception occurring
is not Throwable, in which case the default handler would execute and the
exception key would get set, the other time your own handler fires and it
doesn't get set.
No, wait, I'm not sure that makes sense... where you say "my code looks
like this", is this the code in whatever err100.do maps to (an Action I
assume)? If so, then maybe this does make sense.
Well, even if I am wrong, I think there is an easy way to find out... add
the line:
request.setAttribute(Globals.EXCEPTION_KEY, ex);
...in your handler and see if your problem goes away.
--
Frank W. Zammetti
Founder and Chief Software Architect
Omnytex Technologies
http://www.omnytex.com
AIM: fzammetti
Yahoo: fzammetti
MSN: fzammetti@hotmail.com
On Thu, February 2, 2006 12:49 pm, Michael Davis said:
> Hello,
>
> I'm working on a struts application which has just been deployed and is
> being used by a large number of users. I've got an error handler set up
> using the global-exceptions tag. It sends me an email whenever it
> catches an exception.
>
> My config looks like this:
>
> <global-exceptions>
> <exception type="java.lang.Throwable"
> key="error.error"
> path="/err100.do"/>
> </global-exceptions>
>
> And my code does this:
>
> Throwable e = (Throwable) request.getAttribute( Globals.EXCEPTION_KEY );
>
> (remember that Globals.EXCEPTION_KEY is
> "org.apache.struts.action.EXCEPTION").
>
> Now my problem is that about half the time, e is null, so I can't
> determine where the exception happened or even what it is.
>
> Somehow struts is able to invoke my error handler, but sometimes does it
> without setting Globals.EXCEPTION_KEY in the request. When does that
> happen? How can I figure out what caused the error to happen?
>
> thanks very much,
> Michael from Ottawa
>
>
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org