📄 failingconstructor22.java
字号:
// exceptions/FailingConstructor22.java
// TIJ4 Chapter Exceptions, Exercise 22, page 488
/* Create a class called FailingConstructor with a constructor that might fail
* partway through the construction process and throw an exception. In main(),
* write code that properly guards against this failure.
*/
public class FailingConstructor22 {
Integer[] ia = new Integer[2];
String s;
FailingConstructor22(String s) throws Exception {
ia[0] = 0;
ia[1] = 1;
ia[2] = 2;
this.s = s;
}
public static void main(String[] args) {
try {
FailingConstructor22 fc = new FailingConstructor22("hi");
} catch(Exception e) {
System.err.println("Caught Exception in main()");
e.printStackTrace(System.err);
} finally {
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -