⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 7.13rethrowexception.java

📁 JAVA程序设计的源代码
💻 JAVA
字号:
public class RethrowException{
private static int a=10,b=0;
public static void main(String args[]){
try{
divideOperation();
}
catch(ArithmeticException exception){    //捕获被零除的异常
System.out.println("ArithmeticException is handled in mainmethod!");
System.err.println(exception.toString());
}
}
public static void divideOperation () throws ArithmeticException{    //声明被零除的异常
try {
if (b == 0){
System.err.println(" ---  Calling method divideoperation---");
throw new ArithmeticException ("Divided by zero!");    //抛出被零除的异常
}
System.out.println ("a / b =" + a / b);
}
catch (ArithmeticException exception){    //捕获被零除的异常
System.err.println("ArithmeticException is caught in divideOperation method!");
System.err.println("ArithmeticException is thrown in divideOperation method!");
throw exception;
}
}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -