on-internet
← Community

Try catch finally: Do something if no exception is thrown

Stack Overflow ·

I'm wondering, is there a way to only execute a block if no exception was thrown? The best I can come up with is this: bool exception = false; try{ // something }catch(Exception e){ exception = true; }finally{ if(!exception){ // i can do what i want here } } Is there a better way?

Comments

Sign in or sign up to comment and upvote.

No comments yet.