异常
来源:互联网 发布:linux rar压缩命令 编辑:程序博客网 时间:2024/04/29 23:19
class Test
{
public int devide(int x,int y) throws ArithmeticException,DevideByMinueException
{
if(y<0)
throw new DevideByMinueException("除数为"+y);
int result = x/y;
return result;
}
}
class DevideByMinueException extends Exception
{
public DevideByMinueException(String msg)
{
super(msg);
}
}
class SubTest extends Test
{
public int devide(int x,int y) throws ArithmeticException//此处只能抛出父类中存在的异常
{
if(y<0)
throw new ArithmeticException("除数为"+y);
int result = x/y;
return result;
}
}
class TestException
{
public static void main(String args[])
{
try
{
new Test().devide(3,0);
}catch(ArithmeticException ex)
{
System.out.println(" ArithmeticException");
ex.printStackTrace();
}catch(DevideByMinueException ex)
{
System.out.println(" DevideByMinueException");
ex.printStackTrace();
}
catch(Exception ex)//Exception 语句不能放在其他异常语句之前
{
ex.printStackTrace();
System.exit(0);
}
finally
{
System.out.println("finally");
}
}
}
- 异常
- 异常!
- 异常
- 异常
- 异常
- 异常
- 异常
- 异常
- 异常
- 异常
- 异常
- 异常
- 异常
- 异常
- 异常
- 异常
- 异常
- 异常
- (十八)师大放假了 - 2
- 升级U872 SP1后,打开总账账表,提示“功能权限编号[GL***]不存在”
- 添加删除windows组建中米有iis如何安装
- 带编辑的下拉框asp.net
- (十八)师大放假了 - 3
- 异常
- zz"WARNING: terminal is not fully functional" and pro blems with vi
- 在IIS中设置Session”永不过期”的问题
- (十八)师大放假了 - 4
- 深入浅出 Hello world 我深深地感觉到,我这七年,在计算机上,学的太少了!
- Eclipse中的快捷键
- Flex 平铺背景图片
- Google百度和谷歌的那些事
- 7种CSS圆角框解决方案