异常常见类型处理分析
2015-01-08 17:22
357 查看
package cyb.lxf.staring.test;
public class TestMyException {
public static void main(String[] args) {
TestMyException.ex5();
}
public static void ex1() {
try {
int tmp = 1 / 0;
} catch (Exception e) {
System.out.println("ex occur!");
} finally {
System.out.println("finally hadle...");
}
/**
* ex occur!
* finally hadle...
*/
}
public static void ex2() {
try {
int tmp = 1 / 0;
System.out.println("after ex.");//异常后的语句不会执行
return ;
} catch (Exception e) {
System.out.println("ex occur!");
} finally {
System.out.println("finally hadle...");
}
/**
* ex occur!
* finally hadle...
*/
}
public static void ex3() {
try {
int tmp = 1 / 0;
System.out.println("after ex.");//异常后的语句不会执行
return ;
} catch (Exception e) {
System.exit(0);
System.out.println("ex occur!");
} finally {
System.out.println("finally hadle...");
}
/**
* 无输出
*
*/
}
public static void ex4() {
try {
int tmp = 1 / 0;
System.out.println("after ex.");//异常后的语句不会执行
return ;
} catch (Exception e) {
System.out.println("ex occur!");
System.exit(0);//程序非、正常退出,导致finally无法正常处理
} finally {
System.out.println("finally hadle...");
}
/**
* ex occur!
*
*/
}
public static void ex5() {
try {
int tmp = 1 / 0;
System.out.println("after ex.");//异常后的语句不会执行
return ;
} catch (Exception e) {
System.out.println("ex occur!");
return ;//不会影响finally无法正常处理
} finally {
System.out.println("finally hadle...");
}
/**
* ex occur!
* finally hadle...
*/
}
public static void ex6() {
try {
int tmp = 1 / 0;
System.out.println("after ex.");//异常后的语句不会执行
return ;
} catch (Exception e) {
System.out.println("ex occur!");
return ;//不会影响finally无法正常处理
//System.out.println("ex occur!");//语法不通过,return 后的语句永远不会被执行到。
} finally {
return ;
//System.out.println("finally hadle...");//语法不通过,return 后的语句永远不会被执行到。
}
/**
* ex occur!
* finally hadle...
*/
}
//任何单位语句块中,return后边的语句都不能被执行。
}
public class TestMyException {
public static void main(String[] args) {
TestMyException.ex5();
}
public static void ex1() {
try {
int tmp = 1 / 0;
} catch (Exception e) {
System.out.println("ex occur!");
} finally {
System.out.println("finally hadle...");
}
/**
* ex occur!
* finally hadle...
*/
}
public static void ex2() {
try {
int tmp = 1 / 0;
System.out.println("after ex.");//异常后的语句不会执行
return ;
} catch (Exception e) {
System.out.println("ex occur!");
} finally {
System.out.println("finally hadle...");
}
/**
* ex occur!
* finally hadle...
*/
}
public static void ex3() {
try {
int tmp = 1 / 0;
System.out.println("after ex.");//异常后的语句不会执行
return ;
} catch (Exception e) {
System.exit(0);
System.out.println("ex occur!");
} finally {
System.out.println("finally hadle...");
}
/**
* 无输出
*
*/
}
public static void ex4() {
try {
int tmp = 1 / 0;
System.out.println("after ex.");//异常后的语句不会执行
return ;
} catch (Exception e) {
System.out.println("ex occur!");
System.exit(0);//程序非、正常退出,导致finally无法正常处理
} finally {
System.out.println("finally hadle...");
}
/**
* ex occur!
*
*/
}
public static void ex5() {
try {
int tmp = 1 / 0;
System.out.println("after ex.");//异常后的语句不会执行
return ;
} catch (Exception e) {
System.out.println("ex occur!");
return ;//不会影响finally无法正常处理
} finally {
System.out.println("finally hadle...");
}
/**
* ex occur!
* finally hadle...
*/
}
public static void ex6() {
try {
int tmp = 1 / 0;
System.out.println("after ex.");//异常后的语句不会执行
return ;
} catch (Exception e) {
System.out.println("ex occur!");
return ;//不会影响finally无法正常处理
//System.out.println("ex occur!");//语法不通过,return 后的语句永远不会被执行到。
} finally {
return ;
//System.out.println("finally hadle...");//语法不通过,return 后的语句永远不会被执行到。
}
/**
* ex occur!
* finally hadle...
*/
}
//任何单位语句块中,return后边的语句都不能被执行。
}
相关文章推荐
- Java 常见异常类型及原因分析(上)
- 异常处理与常见的异常类型
- JAVA常见异常类型及其原因分析
- 原创:异常处理方式的区别和分析
- 求救!!!各位大哥帮帮忙!未处理的“System.ArithmeticException”类型的异常出现在 system.drawing.dll 中.
- 使用Boolean类型同步锁引起异常的分析
- 使用Boolean类型同步锁引起异常的分析
- Scope中的异常处理类型
- 使用DLL时如何处理“System.NullReferenceException”类型的异常
- JAVA编程中异常问题处理方式的区别和分析
- (转)J2SE综合:JAVA异常处理方式的区别和分析。
- 未处理的“System.ComponentModel.Win32Exception”类型的异常出现在 System.dll 中 解决一法
- 硬盘不能启动的常见故障分析及处理
- dataType参数不能为空,未处理的“System.ArgumentNullException”类型的异常出现在 mscorlib.dll 中
- struts 常见异常分析
- JAVA编程中异常问题处理方式的区别和分析
- 编译提示“未处理的‘System.ArithmeticException’类型的异常出现在 system.drawing.dll”
- Hibernate 常见异常处理(转帖)
- JAVA编程中异常问题处理方式的区别和分析
- java常见异常及处理