java 异常处理练习(毕向东)
2014-04-25 20:59
330 查看
package Lianxi; class LanPingException extends Exception { LanPingException(String message) { super(message); } } class MaoYanException extends Exception { MaoYanException(String message) { super(message); } } class NoPlanException extends Exception { NoPlanException(String message) { super(message); } } class Computer { private int state= 3; public void run()throws LanPingException,MaoYanException { if(state==2) throw new LanPingException("蓝屏了"); if(state==3) throw new MaoYanException("冒烟了"); System.out.println("电脑运行"); } public void reset() { state=1; System.out.println("电脑重启"); } } class Teacher { private String name; private Computer cmpt; Teacher(String name) { this.name = name; cmpt = new Computer(); } public void prelect()throws NoPlanException { try { cmpt.run(); } catch (LanPingException e) { cmpt.reset(); } catch (MaoYanException e) { test(); throw new NoPlanException("课时无法继续"+e.getMessage()); } System.out.println("讲课"); } public void test() { System.out.println("lianxi"); } } public class Demo001 { public static void main(String [] args) { Teacher t = new Teacher("张老师"); try { t.prelect(); } catch(NoPlanException e) { System.out.println(e.toString()); System.out.println("换老师,或者换电脑或者放假"); } } }
相关文章推荐
- Java开发练习5,异常处理
- java练习——多态与异常处理
- java中的String类的练习(来自毕向东老师视频资料)
- 异常处理——毕向东Java基础教程学习笔记
- 【java】毕向东异常练习
- 黑马程序员_毕向东Java基础_String类练习
- JAVA练习---人民币小写转大写
- SPARK java.io.NotSerializableException 异常处理
- java基本数据类型练习
- java(Collection接口)练习07
- java例程练习(Point类及简单测试)
- java反射练习02
- 【Java】学习笔记——异常处理
- java基础练习 7
- 蓝桥杯java练习——考察团组成
- Java编程思想 第4版 练习题 / 第2章 一切都是对象 / 练习5
- java例程练习(继承中的构造函数)
- 蓝桥杯java练习——递归算法细菌增值
- Java课程教学方法探讨——练习企业真实项目
- java练习-01字串