📄 testexception.java
字号:
class MyException extends Exception
{
int r;
public MyException(String msg,int r)
{
super(msg);
this.r=r;
}
public int getR()
{
return r;
}
}
class Test
{ int r;
public double area(int r)throws ArithmeticException,MyException
{
this.r=r;
if(r<0)
throw new MyException("半径为负数了",r);
double result=3.14*r*r;;
return result;
}
}
public class TestException
{
public static void main(String args[])
{
try{double result=new Test().area(-3);
System.out.println("the result is"+result);
}
catch(MyException e1){
System.out.println("is MyException");
System.out.println(e1.getMessage());
System.out.println("the R is "+e1.getR());
}
finally{
System.out.println("program is running into finally");
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -