class MaoYanException extends Throwable
{
MaoYanException(String msg)
{
super(msg);
}
}
class LanPingException extends Throwable
{
LanPingException(String msg)
{
super(msg);
}
}
class NoPlanException extends Throwable
{
NoPlanException(String msg)
{
super(msg);
}
}
class Computer
{
private int state = 0;
public void run()throws LanPingException,MaoYanException
{
if(state ==1)
throw new LanPingException("diannaolanping");
if(state ==2)
throw new MaoYanException("diannaomaoyan");
System.out.println("computer run");
}
public void reset()
{
state = 0;
}
class Teacher
{
private String name;
private Computer comp;
Teacher(String name)
{
this.name = name;
comp = new Computer ();
}
public void test()
{
System.out.println("everybody test");
}
public void prelect()throws NoPlanException
{
try
{
comp.run();
System.out.println("teach");
}
catch (LanPingException e)
{
System.out.println(e.toString());
comp.reset();
prelect();
}
catch (MaoYanException e)
{
System.out.println(e.toString());
test();
throw new NoPlanException("can't finash"+e.getMessage());
}
}
}}
class ExceptionDemo
{
public static void main (String[] args)
{
Teacher t = new Teacher("teacherBi");
try
{
t.prelect();
}
catch (MaoYanException e) / /在相应的try语句中不能抛出异常错误MaoYanException
{
System.out.println(e.toString()+".....");
System.out.println("changeteacher");
}
}
}
刚开始的错误是 错误:一种是无法将类Exception中的构造器Exception应用到给定类型。另一种是不兼容的类型 需要Throwble 然后我把几个异常类继承Throwble 替换了之前的继承Exception。就出现了 / /在相应的try语句中不能抛出异常错误MaoYanException的错误提示。
{
MaoYanException(String msg)
{
super(msg);
}
}
class LanPingException extends Throwable
{
LanPingException(String msg)
{
super(msg);
}
}
class NoPlanException extends Throwable
{
NoPlanException(String msg)
{
super(msg);
}
}
class Computer
{
private int state = 0;
public void run()throws LanPingException,MaoYanException
{
if(state ==1)
throw new LanPingException("diannaolanping");
if(state ==2)
throw new MaoYanException("diannaomaoyan");
System.out.println("computer run");
}
public void reset()
{
state = 0;
}
class Teacher
{
private String name;
private Computer comp;
Teacher(String name)
{
this.name = name;
comp = new Computer ();
}
public void test()
{
System.out.println("everybody test");
}
public void prelect()throws NoPlanException
{
try
{
comp.run();
System.out.println("teach");
}
catch (LanPingException e)
{
System.out.println(e.toString());
comp.reset();
prelect();
}
catch (MaoYanException e)
{
System.out.println(e.toString());
test();
throw new NoPlanException("can't finash"+e.getMessage());
}
}
}}
class ExceptionDemo
{
public static void main (String[] args)
{
Teacher t = new Teacher("teacherBi");
try
{
t.prelect();
}
catch (MaoYanException e) / /在相应的try语句中不能抛出异常错误MaoYanException
{
System.out.println(e.toString()+".....");
System.out.println("changeteacher");
}
}
}
刚开始的错误是 错误:一种是无法将类Exception中的构造器Exception应用到给定类型。另一种是不兼容的类型 需要Throwble 然后我把几个异常类继承Throwble 替换了之前的继承Exception。就出现了 / /在相应的try语句中不能抛出异常错误MaoYanException的错误提示。
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货