java 基础(异常练习)
2015-12-07 14:18
603 查看
class LpException extends Exception { LpException(String message) { super(message); } } class SmokeException extends Exception { SmokeException(String message) { super(message); } } class NoteException extends Exception { NoteException(String message){ super(message); } } class Computer { private int state=3; void run()throws LpException,SmokeException { System.out.println("start"); if(state==2) throw new LpException("langpin"); if(state==3) throw new SmokeException("smoke"); } void close() { state=1; System.out.println("stop"); } } class Teacher { private String name; Computer pc; Teacher(String name) { this.name =name; pc=new Computer(); } void teaching()throws NoteException { try { pc.run(); } catch(LpException e) { pc.close(); } catch(SmokeException e) { test(); throw new NoteException(e.getMessage()+" break"); } System.out.println("teaching"); } void test() { System.out.println("testing"); } } class MI { public static void main(String[] args) { Teacher t=new Teacher("bi"); try { t.teaching(); } catch(NoteException e) { System.out.println(e.toString()); System.out.println("change"); } } }
相关文章推荐
- java多线程--线程中断
- Windows+JDK6环境配置
- Eclipse编辑jsp、js文件时出现卡死解决方案~
- Spring+Springmvc+MyBatis整合
- Dubbo与Zookeeper、SpringMVC整合和使用
- 常用加密算法的Java实现(一) ——单向加密算法MD5和SHA
- 实现apk 调用framework java JNI中方法
- Spring MVC 4.2 RESTFUL风格返回JSON数据406错误处理
- 【Struts2】(6)拦截器
- java Date的例子
- 常用加密算法的Java实现总结(二) ——对称加密算法DES、3DES和AES
- 底层方法测试--【Java】
- myeclipse 与Eclipse web工程相互导入部署
- 诊断Java中的内存泄露
- java泛型程序设计——定义简单泛型类+泛型方法
- JDK的下载地址
- Java GC - 监控回收行为与日志分析
- java远程执行调试类
- struts2文件下载及文件名中文问题
- spring mvc 使用session