2015-12-15 11:47:04 -08:00
|
|
|
// exceptions/ConstructorException.java
|
|
|
|
// (c)2016 MindView LLC: see Copyright.txt
|
|
|
|
// We make no guarantees that this code is fit for any purpose.
|
2016-09-23 13:23:35 -06:00
|
|
|
// Visit http://OnJava8.com for more book information.
|
2015-12-15 11:47:04 -08:00
|
|
|
|
|
|
|
class CE extends Exception {}
|
|
|
|
|
|
|
|
class SecondExcept extends Reporter {
|
|
|
|
public SecondExcept() throws CE {
|
|
|
|
super();
|
|
|
|
throw new CE();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public class ConstructorException {
|
|
|
|
public static void main(String[] args) {
|
2016-09-06 12:32:51 -06:00
|
|
|
try(
|
|
|
|
First f = new First();
|
|
|
|
SecondExcept s = new SecondExcept();
|
|
|
|
Second s2 = new Second()
|
|
|
|
) {
|
2015-12-15 11:47:04 -08:00
|
|
|
System.out.println("In body");
|
|
|
|
} catch(CE e) {
|
|
|
|
System.out.println("Caught: " + e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* Output:
|
|
|
|
Creating First
|
|
|
|
Creating SecondExcept
|
|
|
|
Closing First
|
|
|
|
Caught: CE
|
|
|
|
*/
|