I have this gist and I wondered why it’s the case that an assert caught in the body of a future fails silently rather than going to the catch
clause, whilst a normal throw
is caught correctly.
Anyone are to give an explanation for this?
I have this gist and I wondered why it’s the case that an assert caught in the body of a future fails silently rather than going to the catch
clause, whilst a normal throw
is caught correctly.
Anyone are to give an explanation for this?
Your second snippet doesn’t print the error either. An AssertionError
is not a subclass of Exception
apparently. If you want to catch it you’ll have to catch a Throwable
.
Shoot! you’re right. Ok makes sense.
For searchers, Exceptions and Errors are distinct in Java & the JVM. Errors are typically things that you don’t want to catch, so you should nearly always catch Exception rather than Throwable if you need a very broad catch block. Errors usually indicate either a programming error that should be fixed (as with assertions) or a condition that can’t be recovered from (out of memory, system shutdown, etc.)
This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.