First page Back Continue Last page Summary Text
Notes:
I want to make the point that both checked and unchecked exceptions must be considered when reviewing code for exception safety.
Why must unchecked exceptions be considered? Because they can be caught.
And, when they are caught, the code that catches them requires guarantees about the state of the system. If, for example, it is going to restart the subsystem that encountered the problem, then it needs to know that the subsystem died in an orderly manner. I, for one, do not consider handling java.lang.OutOfMemoryError an unreasonable thing for an application to do!
Throughout this article whenever I mention exceptions without qualification I mean it in the inclusive sense either checked or unchecked exception. Because of this, and because a method that doesnt catch an exception doesnt care about the type of the exception, throws clauses are of little account when reasoning about exception safety.
That last point might seem a surprise if you've not thought it through before. Im sure weve all had the experience of a null pointer exception or out of memory exception interrupting our code from a routine that doesnt throw any checked exceptions. If we cant handle that then our code isnt exception safe.