2 ms·
> Don’t catch fatal exceptions; nothing you can do about them anyway, and trying to generally makes it worse. Yes there is something: you can design an excepti
by kazinator 1y ago
> Don’t catch fatal exceptions; nothing you can do about them anyway, and trying to generally makes it worse.
Yes there is something: you can design an exception handling system which lets your code specify choices about what to do if such an exception occurs within its contour. Those choices provide ways of passing control to that code.
Then the next layers above the code can decide whether to take those choices, or some other similar choices available from eslewhere, or let the exception bubble up, possibly leaving it unhandled.
The article is a decent tutorial for working with Blub exceptions, but it's limited to that.
- samus 1y agoThat's try-catch. But you missed the point: you can't do anything about fatal exceptions such as an OutOfMemoryError.
- kazinator 1y agoUntrue. The circumstances of an OOM can be arranged in such a way that an emergency stash of a small amount of memory is available to meet the needs of some clean-up task.
- samus 1y agoThose stashes (and things like caches) should use SoftReferences so the GC can drop them under memory pressure. That way no funny stuff needs to happen in catch blocks.