1

Is there a way to get the class from where the @ControllerAdvice got its control.

I.e.: If and execution of PersonController is going on and I get some error due to which the control transferred to the @ControllerAdvice class's method handleException(...).

Is there a way to get the PersonController class name inside the handleException method with Spring 3.2.3.

Any other way to achieve this?

Thank you for reading.

ℛɑƒæĿᴿᴹᴿ
  • 4,983
  • 4
  • 38
  • 58
Bilbo Baggins
  • 2,899
  • 10
  • 52
  • 77

1 Answers1

1

You can call the getStackTrace against your exception, first entry will give you the originating class

 handleException(YourException ex) {
    String exceptionController = ex.getStackTrace()[0].getClassName();
    ...
 }
Master Slave
  • 27,771
  • 4
  • 57
  • 55
  • Now suppose if I am not rethrowing the exception at controller level, then in that case the class I will get will be manager layer class as the exception is thrown from there, is there a way that I can get the controller name? – Bilbo Baggins Jan 07 '15 at 07:19
  • How can I get the request Param? – PAA Jan 23 '20 at 16:29