First page Back Continue Last page Summary Text
Notes:
The exception safety landmarks are as useful in Java as in C++: the basic, strong and nothrow guarantees clearly make sense and can be applied when writing or reviewing code. I have illustrated techniques for writing code to these guarantees.
Unchecked exceptions encapsulate a number of problems these include both clear programming errors (e.g. index out of bounds) that shouldnt happen in a correct program and rare but plausible events (e.g. out of memory). Because they include the latter it is unreasonable to ignore them.
I can appreciate the path that led Java to the current handling of unchecked exceptions rather than the JVM having undefined behaviour when bad things happen the behaviour is defined (specifically unchecked exceptions are thrown). But this has only shifted the problem because the programmer is not working with the raw JVM, but with library code that doesnt fully document its behaviour.
In addition to unchecked exceptions being undocumented, there are no compile-time tools for verifying exception safety. This once again leaves the problem with the developers who must document and check the requirements for themselves.
A bad example is set by the standard library: we met the example of java.awt.Graphics.dispose() earlier.