posted 22 years ago
The following question is asked (Chapter 5, Question 9 in second edition of RHE):
"Which one of the following fragments shows the most appropriate way to throw an exception? Assume that any undeclared variables have been appropriately declared elsewhere and are in scope and have meaningful values."
The correct answer is given as:
B) 1. if (!f.exists()) { // f is a File object
2. throw new IOException("File " + f.getName() + " not found");
3. }
Yet, if the file is not found, it won't be able to get to its hands on the method "getName". Is my reasoning right here? The correct answer should then be:
E) 1. if (!f.exists()) { // f is a File object
2. throw new IOException();
3. }
Please let me know what I'm missing...
[ January 15, 2002: Message edited by: Adi du Toit ]