On Sun, 10 Jul 2016 16:57:49 +0000, ketmar wrote: > On Sunday, 10 July 2016 at 16:47:31 UTC, Chris Wright wrote: >> You do need a try/catch in every annotated function to catch runtime >> exceptions like OutOfMemoryError. > > as a side note: it is even not guaranteed that one *can* catch Error.
This is just plain wrong. The spec explicitly talks about catching Error (in the docs about TryStatement) and how to do it. I guess in the most general case, you're not guaranteed that your CPU won't catch fire in between the throw statement and the catch block? In which case we might as well throw out all programming -- and cognition, since I might get hit by a meteor while I'm pondering. > and it is plainly wrong to try to continue execution after that, as > program is in undefined state. Also wrong. The spec defines the differences between Error and other Throwables. It involves how exception chaining works, if you throw an exception while handling an exception. It notably does not say that your program is in an undefined state after catching an Error. You might be saying that I could forget to clean up resources or restore invariants after an Error is thrown. But that's also true of any Throwable. Or a return statement. Again, if this sort of error bothers you so much that you refuse to write any code that could trigger it, you can't write *any* code.