java - Catch exception by class? -


i catch exception expect allow others through.

the solution have come @ moment is:

protected void perfromcall(class expectedexception) throws exception {     try {         response = call.call(request);     } catch (exception e) {         if (!expectedexception.isinstance(e)) {             throw new exception(e);         }     } } 

while silently eat expected exception , throw others, don't wraps unexpected exceptions , have catch unexpected in caller whereas (before trying silently catch expected exceptions) let them bubble test framework fail test.

is there cleaner way "i expected exceptions of class a, other exception, let thrown chain until it's handled test framework above"?

edit: wanted provide justification why want there answers (now deleted) questioned silently eating exception. test framework calls service. of tests pass bad arguments service, expect exception thrown service due catching invalid request. therefore want silently eat expected exception, still let unexpected exceptions bubble , fail test.

protected void perfromcall(class<?> expectedexception) throws exception {     try {         response = call.call(request);     } catch (exception e) {         if (!expectedexception.isinstance(e)) {             throw e;         }     } } 

Comments

Popular posts from this blog

Add email recipient to all new Trac tickets -

400 Bad Request on Apache/PHP AddHandler wrapper -

php - Change action and image src url's with jQuery -