First page Back Continue Last page Summary Graphics
We need nothrow guarantees
The last example uses the nothrow guarantee for:
- The "swap" code that updates the object (system)
- This is OK as it is guaranteed for assigining references
- The "dispose" code that releases resources
- This is only OK if the method makes the promise
Notes:
The remarks in the previous section should make it clear that once we start to update the system state we needed to restrict ourselves to operations that dont throw exceptions.
The more one works with exceptions the more it becomes apparent that there are sequences of operations that need to complete without error. The basic minimum is the ability to swap a new internal state for the old one and to release any freed resources. We see this in action in the last section where the new internal state is constructed before the pivot and then comes the swap and release sequence.
This is an area in which the Java standard library documentation is deficient it only addresses checked exceptions. Consider, for example, java.awt.Graphics.dispose() could this propagate an out of memory, 'null pointer' (or other unchecked) exception? I hope not - but without documentation of this point we dont know.