I want a hack here. What I am trying out is to execute some of the business logic after throwing an exception. The business logic is defined in the catch block. I don't want to keep the throw statement at the end of the catch block. Is there any hack I can try? What I am thinking is to create a thread in that point and inside that throw the exception. I am not sure whether it will work or not. Please help me out.
package demo1.web;
import demo.exceptions.SupportInfoException;
public class TestInnerException {
void testIt() throws Exception{
try{
int i=0;
int j=1/i;
}catch(Exception e){
System.out.println("business logic .. .. . . ");
throw e;
// I want to excute these below line ,
but it is unreachable because you aleready throwing the excetion ..
//any Hacks for it ?
System.out.println("Lines after throwing the exception ... .");
}
System.out.println("I want this logic to be run . . . . .");
}
public static void main(String[] args) throws SupportInfoException, Exception {
TestInnerException t = new TestInnerException();
t.testIt();
}
void testRunTimeEx(){
int i=0;
int j=1/i;
}
}
Let me tell you my scenario , I am having @ExceptionHandler annotation to handle all the exception as described in this post . https://spring.io/blog/2013/11/01/exception-handling-in-spring-mvc#user-content-sample-application Some complex scenario , cant explain why exactly . What i want here is if it is handled by catch block then i want that to be triggered in @ExceptionHandler because there i have some other Business logic . The problem is @ExceptionHandler is not triggered unless exception is thrown. I want that to be triggered if it entered the catch block. But Its not triggered if the catch block doesnt throw any exception.
Business logic in this context I mean as some Logging Function.