编写了一个异常类,在编译时出现了异常?该怎么解决?
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;
}
}
class DevideByMinusException extends Exception
{
public DevideByMinusException(String mess)
{
super(mess);
}
}
class TestException
{
public static void main(String [] args)
{
try
{
new Test().devide(3,-1);
}
catch(ArithmeticException e)
{
System.out.println("program is running into ArithMetic");
e.printStackTrace();
}
catch(DevideByMinusException e)
{
System.out.println("program is running into DevideByMinus");
e.printStackTrace();
}
catch(Exception ex)
{
System.out.println(ex.getMessage());
}
finally
{
System.out.println("close the files");
}
System.out.println("program is running here!");
}
}
在我的机器上运行的结果是这样的:
.\Exception.java:1: duplicate class: Test
class Test
^
.\Exception.java:12: duplicate class: DevideByMinusException
class DevideByMinusException extends Exception
^
.\Exception.java:19: duplicate class: TestException
class TestException
^
Exception.java:12: cannot access Exception
bad class file: .\Exception.java
file does not contain class Exception
Please remove or make sure it appears in the correct subdirectory of the classpa
th.
class DevideByMinusException extends Exception
^
4 errors