本帖最后由 王红霞 于 2012-7-17 01:04 编辑
在看毕老师的视频的时候想不通……
class LpException extends Exception
{
LpException(String message)
{
super(message);
}
}
class MyException extends Exception
{
MyException(String message)
{
super(message);
}
}
class Computer
{
private state=1;
public void run()
{
if(state==2)
throw new LpException("蓝屏了");
if(state==3)
throw new MyException("冒烟了");
System.out.println("run computer");
}
public void reset()
{
System.out.println("reset computer");
}
}
class Teacher
{
private String name;
private Computer cmpt;
Teacher(String name)
{
this.name=name;
cmpt=new Computer();
}
public void prelect() throws MyException
{
try
{
cmpt.run();
}
catch (LpException e)
{
cmpt.reset();
}
catch (MyException e)
{
throw e;//如果下个程序还是不能处理这个异常 假设一直将这个异常抛下去 会不会产生死锁(对于最后那个接受异常的的程序来说)?有没有什么规则规定了异常最多抛几个程序?如果产生了死锁感觉解决起来会很麻烦是不是?不懂
}
System.out.println("teach");
}
}
class ExceptionTest
{
public static void main(String[] args)
{
Teacher t=new Teacher("doc. bi");
t.prelect();
}
}
|