动手动脑:多层的异常捕获
2015-11-15 11:56
239 查看
示例1
public class CatchWho {
public static void main(String[] args) {
try {
try {
throw new ArrayIndexOutOfBoundsException();
}
catch(ArrayIndexOutOfBoundsException e) {
System.out.println( "ArrayIndexOutOfBoundsException" + "/内层try-catch");
}
throw new ArithmeticException();
}
catch(ArithmeticException e) {
System.out.println("发生ArithmeticException");
}
catch(ArrayIndexOutOfBoundsException e) {
System.out.println( "ArrayIndexOutOfBoundsException" + "/外层try-catch");
}
}
}
示例2
public class CatchWho2 {
public static void main(String[] args) {
try {
try {
throw new ArrayIndexOutOfBoundsException();
}
catch(ArithmeticException e) {
System.out.println( "ArrayIndexOutOfBoundsException" + "/内层try-catch");
}
throw new ArithmeticException();
}
catch(ArithmeticException e) {
System.out.println("发生ArithmeticException");
}
catch(ArrayIndexOutOfBoundsException e) {
System.out.println( "ArrayIndexOutOfBoundsException" + "/外层try-catch");
}
}
}
public class CatchWho {
public static void main(String[] args) {
try {
try {
throw new ArrayIndexOutOfBoundsException();
}
catch(ArrayIndexOutOfBoundsException e) {
System.out.println( "ArrayIndexOutOfBoundsException" + "/内层try-catch");
}
throw new ArithmeticException();
}
catch(ArithmeticException e) {
System.out.println("发生ArithmeticException");
}
catch(ArrayIndexOutOfBoundsException e) {
System.out.println( "ArrayIndexOutOfBoundsException" + "/外层try-catch");
}
}
}
示例2
public class CatchWho2 {
public static void main(String[] args) {
try {
try {
throw new ArrayIndexOutOfBoundsException();
}
catch(ArithmeticException e) {
System.out.println( "ArrayIndexOutOfBoundsException" + "/内层try-catch");
}
throw new ArithmeticException();
}
catch(ArithmeticException e) {
System.out.println("发生ArithmeticException");
}
catch(ArrayIndexOutOfBoundsException e) {
System.out.println( "ArrayIndexOutOfBoundsException" + "/外层try-catch");
}
}
}
相关文章推荐
- Android Studio的使用(二)--Debug调试
- 没有用数据库却提示我Could not obtain connection metadata
- C#与USB设备通信
- 9个信号说明身体需要检修
- 中国互联网史上十大合并案
- Spark 1.5.0 远程调试
- Eclipse设置编码问题
- LeetCode:Lowest Common Ancestor of a Binary Search Tree
- 大道至简七八章读后感
- Android Volley源码分析(二) 核心功能解析
- cenos7.1 安装openstack kilo 心得之五 安装Database
- 利用未授权的redis写webshell
- 位运算
- 深入浅析JavaScript中prototype和proto的关系
- linux 查看文件(夹)大小
- Flask Web开发
- java之Class Loading Architecture --《Java_Security_2nd_Edition》
- Qt 窗口等设置
- fullfile
- shell读取文件每一行的方式