📄 myexception.java
字号:
//自己定义异常类,并用 throw 语句来抛出它
public class MyException
{
static void Method(int a) throws ExceptionDemo
{
System.out.println("\t调用方法Method("+a+"0");
if(a>10|a<0)
throw new ExceptionDemo(a);
System.out.println("\t正常退出.");
}
public static void main(String[] aa)
{
try
{
Method(1);
Method(-3);
}
catch(ExceptionDemo e)
{
System.out.println("\t捕获异常:"+e.toString());
}
}
}
class ExceptionDemo extends Exception
{
private int detail;
ExceptionDemo(int a)
{ detail = a; }
public String toString()
{
return " exceptionDemo"+detail;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -