----------------解决方案--------------------------------------------------------
class Test
{
public int devide(int x,int y) throws ArithmeticException,DevideByMinusException
{
if(y<0)
throw new DevideByMinusException("devide is "+y);
int result=x/y;
return result;
}
}
class DevideByMinusException extends Exception
{
public void DevidebyMinusException (String msg)
{
super(msg);
}
}
class TestException
{
public static void main(String args [])
{
try
{
System.out.println(new Test().devide(3,1));
}
catch(DevideByMinusException e)
{
System.out.println("program is running into DevideByMinus");
e.printStackTrace();
}
catch(ArithmeticException e)
{
System.out.println("program is running into Arithmetic");
e.printStackTrace();
}
catch(Exception e)
{
System.out.println(e.getMessage());
}
System.out.println("program is running here!");
}
}
我按书上打的怎么也运行不了为什么啊
----------------解决方案--------------------------------------------------------
哪里会运行不了
----------------解决方案--------------------------------------------------------
你能运行?
我怎么提示:
Microsoft Windows XP [版本 5.1.2600]
(C) 版权所有 1985-2001 Microsoft Corp.
F:\学习\作业\JAVA编程>javac 11.java
11.java:6: 找不到符号
符号: 构造函数 DevideByMinusException(java.lang.String)
位置: 类 DevideByMinusException
throw new DevideByMinusException("devide is "+y);
^
11.java:15: 对 super 的调用必须是构造函数中的第一个语句
super(msg);
^
2 错误
----------------解决方案--------------------------------------------------------
千里冰封 看过来
----------------解决方案--------------------------------------------------------
class Test
{
public int devide(int x,int y) throws ArithmeticException,DevideByMinusException
{
if(y<0)
throw new DevideByMinusException("devide is "+y);
int result=x/y;
return result;
}
}
class DevideByMinusException extends Exception
{
public DevideByMinusException (String msg)
{
super(msg);
}
}
class TestException
{
public static void main(String args [])
{
try
{
System.out.println(new Test().devide(3,1));
}
catch(DevideByMinusException e)
{
System.out.println("program is running into DevideByMinus");
e.printStackTrace();
}
catch(ArithmeticException e)
{
System.out.println("program is running into Arithmetic");
e.printStackTrace();
}
catch(Exception e)
{
System.out.println(e.getMessage());
}
System.out.println("program is running here!");
}
}
不知道你写些什么程序,连抄都会抄错,真是人才
现在已经帮你改好了,就是些大小些的问题,还有你构造函数加了void
以后学习要小心点.不要这么马虎
还有,你的错误信息已经很清楚的告诉你哪里有问题了
----------------解决方案--------------------------------------------------------