📄 nestedtry.java
字号:
/**
* 这个类演示嵌套 try-catch语句。
*
* @version 1.0 2005 年 6 月 2 日
* @author Michael
*/
package SG5.Example4;
class NestedException {
/** 构造函数。 */
protected NestedException() {
}
/** 这个方法检测试数字的格式。
* @param argument 用于存储 args 的值。
*/
public void test(final String[] argument) {
try {
System.out.println("传递的参数是: " + argument[0]);
/* 嵌套 try 块。 */
try {
/* 类型转换 */
int numValue = Integer.parseInt(argument[0]);
System.out.println(argument[0] +"的平方" + "是"
+ numValue * numValue);
} catch (NumberFormatException nb) {
/** 如果发生异常,则显示相应的消息。
*/
System.out.println("不是一个数! ");
}
} catch (ArrayIndexOutOfBoundsException ne) {
System.out.println("请输入数字!!!");
}
}
}
/**
* 这是 main 类。
*/
class NestedTry {
/** 构造函数。 */
protected NestedTry() {
}
/**
* 类和应用程序的唯一进入点。
* @param args 字符串参数的数组。
*/
public static void main(String[] args) {
NestedException obj = new NestedException();
obj.test(args);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -