📄 arithmeticexception.java
字号:
/*
* (c) 2005 Aptech Limited
* 版权所有
*/
/**
* 这个类生成一个算术异常。
*
* @version 1.0 2005 年 5 月 22 日
* @author Michael
*/
package SG5.Example1;
class ExceptionRaised {
/** 构造函数。 */
protected ExceptionRaised() {
}
/**
* 这个方法生成一个异常。
* @param operand1 是除法中的分子
* @param operand2 是除法中的分母
* @return 它将返回除法的余数。
*/
static int calculate(final int operand1, final int operand2) {
int result = operand1 / operand2; // 用户自定义方法
return result;
}
}
/**
* 这是 main 类。
*
*/
public class ArithmeticException {
/** 构造函数。 */
protected ArithmeticException() {
}
/**
* 唯一的条目指向类和应用程序的唯一进入点。
* @param args 字符串参数的数组。
*/
public static void main(String[] args) {
ExceptionRaised obj = new ExceptionRaised();
try {
/* 定义变量 result 以存储结果。 */
int result = obj.calculate(9, 0);
System.out.println(result);
} catch (Exception e) { // 异常对象
System.err.println("发生异常:" + e.toString());
e.printStackTrace();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -