facebook

struts exception handling

  1. MyEclipse IDE
  2.  > 
  3. Off Topic
Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #253244 Reply

    David
    Member

    I have a question about using struts 1.2 custom exception handling. I have the class:

    public class SystemException extends ExceptionHandler {

    public ActionForward execute(…) {

    forward = mapping.getInputForward();
    return forward;
    }

    In my struts-config file I have:

    <global-exceptions>
    <exception handler=”com.company.common.exceptions.SystemException”
    key =”unexpected.error”
    type=”java.lang.NullPointerException”
    path=”SystemExceptionPage”
    scope=”request”/>
    </global-exceptions>

    I have a class that extends Thread with a run() which is a call to a class that is throwing a specialized exception, which I catch. However, since its a Thread class, I can’t throw an exception. Struts ignores this and never calls my SystemException, so when I get the NullPointer I see the stack trace in the console, but then struts redirects me to the /index.html

    Is there a way for struts to catch exception that is caught in a threaded class?

    #253253 Reply

    Riyad Kalla
    Member

    Does your class have to be threaded? Have you looked at alternatively using asynchronous frameworks like Foxtrot or Spin, I believe both support thrown exceptions when running a task or job (psuedo code):

    
    try
    {
      Runner.runTask(new Task(){.. your code ..});
    }
    catch(SystemException e)
    {
    }
    
    #253299 Reply

    Robert Varga
    Participant

    @sonoerin wrote:

    I have a question about using struts 1.2 custom exception handling. I have the class:

    public class SystemException extends ExceptionHandler {

    public ActionForward execute(…) {

    forward = mapping.getInputForward();
    return forward;
    }

    In my struts-config file I have:

    <global-exceptions>
    <exception handler=”com.company.common.exceptions.SystemException”
    key =”unexpected.error”
    type=”java.lang.NullPointerException”
    path=”SystemExceptionPage”
    scope=”request”/>
    </global-exceptions>

    I have a class that extends Thread with a run() which is a call to a class that is throwing a specialized exception, which I catch. However, since its a Thread class, I can’t throw an exception. Struts ignores this and never calls my SystemException, so when I get the NullPointer I see the stack trace in the console, but then struts redirects me to the /index.html

    Is there a way for struts to catch exception that is caught in a threaded class?

    The reason why your exception handler was not notified is because an exception was never thrown in the thread handling the http request.

    You should decide what you are trying to do:

    – if you want asynchronous execution (separate thread), that means, that you do not wait for the outcome of the threaded operation, but provide an output regardless of the outcome of that thread. this way you can be made aware of the outcome of the other thread in a later coming other http request (polling)

    – if you want to wait for the outcome, then why do you make it a threaded operation at all? just make invoke the operation from the action in the request handler thread, and specify the exception in the struts-config file as it was done.

    Best regards,

    Robert Varga

Viewing 3 posts - 1 through 3 (of 3 total)
Reply To: struts exception handling

You must be logged in to post in the forum log in