关于java异常的问题求解决
课程设计
1
import java.io.*;
class DivisorIsZeroException extends Exception
{
public DivisorIsZeroException(String name)
{
super(name);
}
}
class A
{
public int divide(int a, int b) throws DivisorIsZeroException
{
int m = 0;
if(0 == b)
throw new DivisorIsZeroException("除数不能为零!");
else
m = a / b;
return m;
}
}
public class testexception1
{
public static void main(String[] args)
{
A aa = new A();
try
{
aa.divide(6, 0);
}
catch(Exception e)
{
e.printStackTrace();
System.out.printf("哈哈,出错喽\n");
}
}
}
下面是出错信息
发表回复