大家帮我看看这段关于抛出异常的程序有什么问题,老是说
非法的表达式开始/testOwnerException.java
public class testOwnerException
{
public static void main(String[] args)
{
int x=10;
try
{
System.out.println( "result= "+divide(x,5));
System.out.println( "result= "+divide(x,0));
}
catch(ZeroDivideException e)
{
System.out.println( "found ZeroDivideException! ");
}
catch(ArithmeticExcepion e)
{
System.out.println( "found Arithmetic Exception! ");
}
public static int divide(int dividend,int divisor) throws ZeroDivideException
{
int result=0;
try
{
result=dividend/divisor;
return result;
}
catch(ArithmeticException e)
{
System.out.println( "DO NOT excute divide operation ");
throw new ZeroDivideException(divisor+1);
}
}
}
麻烦大家帮我看看哪里有问题,谢谢
------解决方案--------------------public class testOwnerException
{
public static void main(String[] args)
{
int x=10;
try
{
System.out.println( "result= "+divide(x,5));
System.out.println( "result= "+divide(x,0));
}
catch(ZeroDivideException e)
{
System.out.println( "found ZeroDivideException! ");
}
catch(ArithmeticExcepion e)
{
System.out.println( "found Arithmetic Exception! ");
}
//少了括号
public static int divide(int dividend,int divisor) throws ZeroDivideException