新建 文本文档.txt
来自「小弟自己复习java时候整理的文档,其中包括基础的面向对象的知识及设计模式相关的」· 文本 代码 · 共 48 行
TXT
48 行
class MyException extends Exception
{
private int detail;
MyException(int a)
{
detail = a;
dealThis();
}
public void dealThis()
{
System.out.println("发生了什么什么错误,该怎么做!");
}
public String toString()
{
return "MyExcpetion[" + detail +"]";
}
}
class ExceptionDemo
{
static void compute(int a) throws MyException
{
System.out.println("调用compute(" + a +")");
if(a > 10)
throw new MyException(a);
System.out.println("正常退出!");
}
public static void main(String[] args)
{
try
{
compute(1);
compute(20);
}
catch (MyException e)
{
System.out.println("异常信息:"+ e);
}
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?