throwdemo.java
来自「《Java程序设计》第6、7、8章的源代码。有需要者请」· Java 代码 · 共 20 行
JAVA
20 行
public class ThrowDemo{
public static void main(String []args){
int i;
try{
for(i=1;i<10;i++){
System.out.println(i);
if(i==1)throw new NumberFormatException("Throw Exception1");
if(i==2)throw new ArithmeticException("Throw Exception2");
if(i==3)break;
}
}catch(NumberFormatException e){
System.out.println("捕捉到 NumberFormatException");
}catch(ArithmeticException e){
System.out.println("捕捉到 NumberFormatException");
}finally{
System.out.println("finally块被执行!");
}
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?