A try/catch within a try/catch: which exception handling method is used first?

I have put a try/catch activity within another try/catch activity. Both try/catch activities are trying to catch the same selector not found exception, but with different handling methods. When the exception occurs, which handling method will be used first: the one from the inner try/catch, or the outer try/catch?

My guess is that, the exception handling method from the inner try/catch will be used first, and if the exception still occurs, then the handling method from the outer try/catch will be used.

Thank you very much!


Your guess is correct - it bubbles up until it’s catched.
Although I wouldn’t say “if the exception still occurs”, as it’s inaccurate - exception occurs once.
Outer catch will trigger if there’s either a new exception or the original one is rethrown.

Sidenote - it’s always better to test than to assume:
NestedCatchTest.xaml (8.0 KB)


Thank you so much for your helpful reply!

1 Like

I would always question why a Try Catch is included within a Try Catch? Although I question everything :wink:

1 Like

it’s a game called “Trying to catch the catch” :sweat_smile: but yeah, It’s pretty common, @MatthewCYLau try to use the event to handle the exception before the method try catch.

Please take a look at this Exception Cost: When to throw and when not to

What if there is no “if” like at the end thats kinda the spirit of the try catch nesting here… This information is a gem to me https://www.youtube.com/watch?v=OMPfEXIlTVE&feature=youtu.be - Sandi Metz – Nothing is Something

specially because conditions tends to reproduce… :slight_smile:

I like those Almost Rules. For me it’s as much about simplicity as system performance…

Let’s speak soon yeah :wink:

1 Like