Results 1 to 3 of 3

Thread: Exception handling in spring

  1. #1
    Join Date
    Jun 2011
    Posts
    117

    Default Exception handling in spring

    Hi Guys,

    My requirement is for any exception that is thrown i want to trap it in Exception class.
    Below is my code for that
    Code:
    	@ExceptionHandler(Exception.class)
    	public String handleException(Exception ex) throws IOException {
    		return "newjsp.jsp";
    	    
    	}
    In one of the case I throw nullpointerexception but still it doesnt gets trapped in above funtion. Can you tell me what am i missing
    In Rat race who ever wins or looses still remains the Rat.

  2. #2
    Join Date
    Jan 2008
    Posts
    24

    Default

    First, is the error being thrown in this class? You handler is only going to work in the class it is defined.

    Second, try using
    @ExceptionHandler(Exception.class, NullPointerException.class)

  3. #3
    Join Date
    Jun 2011
    Posts
    117

    Default

    Hi RandyAvis,

    I guessed that but i dont know if i was right anyways thx for your help but i was able to sort my problem of global trapping using old method i.e declaring exceptionHandler in xml


    Thanks and Regards
    Patil Abhijeet
    In Rat race who ever wins or looses still remains the Rat.

Posting Permissions

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