I am using spring's @ControllerAdvice and @ExceptionHandler for exception handling. Any method throws custom exception from Controller and corresponding @ExceptionHandler handle it. If Runtime exception occurs(eg any HibernateException) then it will throw Runtime Exception and I dont have any @ExceptionHandler for RuntimeExceptions.
My question is how to handle any runtime exception? do I need to add @ExceptionHandler for every Exception that is thrown by controller? I dont want create an Generic ExceptionHandler for Exception.class because I have to send different error code according to exception occured.
one way to do it add try catch block in Controller and then throw the custom exception from catch block? or is there any another better way?
All @ExceptionHandlers are inside @ControllerAdvice class.