dividebyzerotry.java
来自「国外的数据结构与算法分析用书」· Java 代码 · 共 23 行
JAVA
23 行
/** Programmer handling of a divide-by-zero exception. */
class DivideByZeroTry
{
public static void main(String[] args)
{
int n, d, r;
try
{
n = 20;
d = 0;
r = n / d; // implicitly throws an exception
System.out.println("This statement is not executed");
} catch (ArithmeticException e) // catch an attempt to divide by zero
{
System.err.println("Attempting to divide by zero");
System.err.println("Exception: " + e);
r = 0; // set r to zero to resume
}
/* Resume normal execution of program. */
System.out.println("r = " + r);
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?