/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