trycatchdemo.java
来自「精通java核心技术》随书源代码」· Java 代码 · 共 22 行
JAVA
22 行
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 + =
减小字号Ctrl + -
显示快捷键?