📄 printexceptionwarning.java
字号:
// 输出异常信息。
class DemonException {
static void generateException() {
int nums[] = new int[5];
System.out.println("Before exception is generated.");
// 产生数组越界异常
nums[10] = 20;
System.out.println("this won't be displayed");
}
}
class PrintExceptionWarning {
public static void main(String args[]) {
try {
DemonException.generateException();
}
catch (ArrayIndexOutOfBoundsException e) {
// 捕捉异常
System.out.println("Standard message is: ");
System.out.println(e);
System.out.println("\nDescription for the exception is: ");
System.out.println(e.getMessage());
System.out.println("\nStack trace: ");
e.printStackTrace(); //输出异常信息
}
System.out.println("\nAfter catch statement.");
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -