java - How do i throw an exception and also execute the remaining business logic in the catch block? -


i want hack here. trying out execute of business logic after throwing exception. business logic defined in catch block. don't want keep throw statement @ end of catch block. there hack can try? thinking create thread in point , inside throw exception. not sure whether work or not. please 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;         // want excute these below line ,          unreachable because aleready throwing excetion ..         //any hacks ?          system.out.println("lines after throwing exception ... .");      }      system.out.println("i want logic 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 scenario , having @exceptionhandler annotation handle exception described in post . https://spring.io/blog/2013/11/01/exception-handling-in-spring-mvc#user-content-sample-application complex scenario , cant explain why . want here if handled catch block want triggered in @exceptionhandler because there have other business logic . problem @exceptionhandler not triggered unless exception thrown. want triggered if entered catch block. not triggered if catch block doesnt throw exception.

business logic in context mean logging function.

it's not hack, perhaps won't make sense.

1) if want throw exception, throw right away.

2) if want business logic on exception raise, , throw exception.

but if want throw , some, not quite possible without dirty code here. seems code smell here me.

edit after question edit :

though logging, still can log before throwing it, there no point generate log after throwing it.


Comments

Popular posts from this blog

c# - Binding a comma separated list to a List<int> in asp.net web api -

Delphi 7 and decode UTF-8 base64 -

html - Is there any way to exclude a single element from the style? (Bootstrap) -