📄 testthrowsexception.java
字号:
class MyException extends Exception {
String NewExceptionObject;
public MyException() {
this.NewExceptionObject="";
}
public MyException(String s) {
this.NewExceptionObject=s;
}
String ShowExceptionInfo() {
return this.NewExceptionObject;
}
}
public class TestThrowsException {
public static void main(String args[]) {
try {
Test();
}
catch(MyException e) {
System.out.println("MyException类:");
System.out.println("已经捕捉到抛出的异常对象!");
System.out.println("异常信息:"+e.ShowExceptionInfo());
}
}
static void Test() throws MyException {
throw new MyException("方法自身产生的异常将由调用者处理!");
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -