Single Catch Block for Multiple Methods in a Class java -


i have class static methods handling memcache requests, has different methods different arguments.

whenever method called in class,i want increment totalrequest counter , if exception occur in of methods inside class want increment failed counter. there way ?

if being static in nature has problems, let me know ? should efficient.

i use aop. if use guice or maven it's quite easy put in place around beans. you'll declare interceptor, guice or maven wrap around methods.

there aspectj have never used it.

finally, wrap calls in caller method. java 8 , lambda, this:

protected <t> t callwithtrace(supplier<t> fn) throws exception {   //some code before call   try {      t output=fn.get();      //code after normal exec      return output;   }   catch(exception e) {      //code in case of error (increase counter??)      throw e;   } }  void someothermethod() {    object ret = callwithtrace({ () -> calltoyourdangerousmethod()});    object ret = callwithtrace({ () -> calltoanotherdangerousmethod()}); } 

with java 7, anonymous inner classes, hard read.


Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -