自己写的demo---声明异常同时处理异常,或者继续抛出异常
2015-11-15 17:24
477 查看
package exception; public class exception { public static void main(String args[]) { /*** * 不能对类型 exception 中的非静态方法 a(int)进行静态引用,想要引用的时候非 * 静态的属性是不能够在静态的方法里引用的,想要引用的话必须是用对象来引用 */ //a(1); //new exception().a(1);//未处理的异常类型 Exception //new exception().a(1);//可以继续抛出声明,这样子就不用try catch了 try { new exception().a(1); } catch (Exception e) { System.out.println("try\tcatch处理了异常"); } } //这种写法会报错 /* public void a(int i) { if(i==1){ throw new Exception();//未处理的异常类型 Exception } }*/ //这种写法没错,但是把异常自己处理了。相当于没卵用 /* public void a(int i) {//抛出异常同时自己处理 if(i==1){ try { throw new Exception(); } catch (Exception e) { // TODO 自动生成的 catch 块 e.printStackTrace(); }//未处理的异常类型 Exception } }*/ public void a(int i) throws Exception {//声明抛出异常 if(i==1){ throw new Exception();//抛出异常 } } }
相关文章推荐
- 对象关系映射ORM?
- 第九周--数据结构--广义表算法库及应用
- HDOJ 4325 Flowers 【线段树 离散化 区间更新 单点查询】
- java 线程中断
- Scala基础入门-4
- 虚拟机检测技术剖析
- 基于AFNetworking封装网络库
- IE 兼容 getElementsByClassName
- http缓存
- 05 ueditor上传图片配置
- 几种排序算法
- ArrayList源码分析(Java&Android)
- 二叉树与哈夫曼树
- kettle4.4在eclipse中运行调试
- 《大道至简》第七章和第八章读后感
- java中的静态导入
- 迭代创建目录
- Java中的基本类型与封装类型以及自动装箱、拆箱、String类型的解释
- This version of the rendering library is more recent than your version of ADT plug-in. Please update
- git安装以及使用