Nitin
Nitin

Reputation: 81

Spring exception handling for common method

I have already developed project but there i see a lot of exception are not properly looged . it did not give proper information about error.

Do we have option to write a common method and confirued it such a way that it will be called first and log the exception in new formate then go with normal flow.so that i do not need to touch the existing class

Upvotes: 0

Views: 73

Answers (1)

QuickSilver
QuickSilver

Reputation: 4045

Declare a class with a method which does custom logging for you and tag that method with @ExceptionHandler and pass list of Exception you would like to handled by that method.

public class FooController{

    //...
    @ExceptionHandler({ CustomException1.class, CustomException2.class, FileNotFoundException.class })
    public void customLogger() {
        //
    }
}

Upvotes: 2

Related Questions