Having studied the SDK1.4 API now, I'll answer my questions for myself:
From chapter 7 onwards, always have the new Java API opened whilst studying the book.
At the end of the chapter on Exceptions Ivor gives an example of how to provide the Exception message with more 'granularity'.
The new 'chained exception facility' uses causes for exactly the same purpose. So assigning a causing Exception to a newly created Exception is an essential feature of the Java language, and should be learned.
The SDK 1.4. API -see: class 'Throwable', explains how causes can be used, with a practical example.
There are two ways to create a 'cause' for any subclass of Throwable:
1. Use a constructor for your exception, that accepts a cause as an argument.
2. Use the Throwable method initCause() to initiate a cause for an existing exception.
|