📄 lesson44.java
字号:
class Test
{
public int devide(int x,int y) throws ArithmeticException,DevideByMinusException
{
if(y<0)
{
throw new DevideByMinusException("devisor is "+y);
}
int result = x/y;
return result;
}
/*
void fun()
{
try
{
if(x==0)
{
throw new XxxException("xxx");
}
else
{
throw new YyyException("Yyy");
}
}
catch(XxxException e)
{
/...
}
catch(YyyException e)
{
/...
}
}
*/
}
class DevideByMinusException extends Exception
{
public DevideByMinusException(String msg)
{
super(msg);
}
}
class TestException
{
public static void main(String[] args) throws Exception
{
try
{
return ;
new Test().devide(3,0);
}
catch(ArithmeticException e)
{
//e.printStackTrace();
System.out.println("b");
}
catch(DevideByMinusException e)
{
System.out.println("a");
}
catch(Exception e)
{
System.out.print(e.getMessage());
}
finally
{
System.out.println("finally");
}
System.out.println("Program is Running!");
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -