ObjectStreamException extends IOException.
NotSerializableException extends ObjectStreamException.
AWTException does not extend any of these.
All are checked exceptions.
The callMe()
method throws NotSerializableException.
What does the following code print out?
Choose all lines that are printed.
try { // w w w . jav a 2 s . c o m callMe(); System.out.println("after call me"); } catch (ObjectStreamException x) { System.out.println("Object stream"); } catch (IOException x) { System.out.println("IO"); } catch (Exception x) { System.out.println("Exception"); } finally { System.out.println("Finally"); }
B, E.
When the exception is thrown, the current pass through the try block is abandoned, so "after call me" isn't printed.
The first catch block that is compatible with the exception's type is executed.
This is the block for ObjectStreamException, which is a superclass of the thrown type.
Only one catch block is executed per thrown exception; execution then continues at the Finally block, which prints "Finally".