首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > Java Exception >

非法的表达式开始

2014-01-26 
/testOwnerException.java public class testOwnerException { public static void main(String[] args){in

/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         

热点排行