Results 1 to 4 of 4
  1. #1
    anjibman is offline Member
    Join Date
    Dec 2010
    Posts
    48
    Rep Power
    0

    Default Assign request variable in catch block

    Hi All,

    Is it valid to do following:
    Java Code:
    try{
         //do something
    } catch(SomeException ex){
         request.setAttribute("status", statusInfo);
    }
    request.setAttribute("status", diffStatusInfo);
    This one is not working for me. I am not able to get status variable in client when there is exception. However I am able to get diffStatusInfo when program runs without exception.

    Any suggestion/comment?

    Thanks.

  2. #2
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    4,041
    Rep Power
    10

    Default Re: Assign request variable in catch block

    You're going to have to be more specific than "not working". What does this do? What did you expect it to do?
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    anjibman is offline Member
    Join Date
    Dec 2010
    Posts
    48
    Rep Power
    0

    Default Re: Assign request variable in catch block

    I am expecting JSP will print
    1. statusInfo value if exception occur
    2. else diffStatusInfo if program run without exception.

  4. #4
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,800
    Rep Power
    7

    Default Re: Assign request variable in catch block

    If an execpetion occurs the attribute will be set to statusInfo. Then execution leaves the catch block and the attribute will be set to diffStatusInfo. What you need to do is move the call to setAttribute inside the try statement.

Similar Threads

  1. Try Catch Block
    By Jackbower in forum New To Java
    Replies: 3
    Last Post: 05-06-2012, 08:00 AM
  2. Try/catch block
    By swati.jyoti in forum New To Java
    Replies: 5
    Last Post: 07-02-2009, 03:32 PM
  3. Question reg try/catch block
    By nn12 in forum New To Java
    Replies: 1
    Last Post: 09-16-2008, 06:56 PM
  4. Try Catch block issues
    By kewlgeye in forum New To Java
    Replies: 11
    Last Post: 04-29-2008, 08:10 AM
  5. try...catch block
    By javaplus in forum New To Java
    Replies: 3
    Last Post: 11-06-2007, 08:53 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •