📄 trycatchdemo.java
字号:
public class TryCatchDemo {
public static void main( String args[] )
{
try {
int number1 = Integer.parseInt(args[0]); // 可能发生NumberFormatException
int number2 = Integer.parseInt(args[1]); // 和ArrayIndexOutOfBoundsException
System.out.println("No NumberFormatException or ArrayIndexOutOfBoundsException occurs! " );
double result = number1 / number2; // 可能发生ArithmeticException
}
catch (NumberFormatException e) {
System.out.println( "Invalid Number Format!" );
}
catch (ArrayIndexOutOfBoundsException e) {
System.out.println( "Array Index Out Of Bounds!" );
}
catch (ArithmeticException e) {
System.out.println( e.toString() );
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -