您的位置:首页 > 其它

在指定方法中抛出异常,在调用该方法的地方处理异常

2014-02-27 15:50 302 查看
public class MethodException
{
public static void main(String args[])
{
Test test=new Test(2,0);
try
{
test.sub(test.a,test.b);
}
catch(Exception x)
{
System.out.println("出现异常!");
}
}
}
class Test
{
int a,b;
public Test(int x,int y)
{
this.a=x;
this.b=y;
}
int sub(int x,int y) throws Exception
{
return  x/y;
}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐