java学习之路-------try....catch....让你想不到的结果
来源:互联网 发布:淘宝二级域名有什么用 编辑:程序博客网 时间:2024/05/18 02:04
一个你会忽略的问题。。。今天被问到了。。。。自己才发现什么也不知道。。。。
第一种:
public class TryCatchTest {
public static void main(String[] args) {
System. out .println(fun());
}
public static String fun(){
try {
int temp =10/0;
return "abc" ;
} catch (Exception e) {
e.printStackTrace();
} finally {
System. out .println("NO" );
}
return "aaa" ;
}
}
结果:
java.lang.ArithmeticException : / by zero
at test.TryCatchTest.fun( TryCatchTest.java:13 )
at test.TryCatchTest.main( TryCatchTest.java:7 )
NO
aaa
第二种
public class TryCatchTest {
public static void main(String[] args) {
System. out .println(fun());
}
public static String fun(){
try {
int temp =10/0;
return "abc" ;
} catch (Exception e) {
e.printStackTrace();
return "aaa" ;
} finally {
System. out .println("NO" );
}
}
}
结果:
java.lang.ArithmeticException : / by zero
at test.TryCatchTest.fun( TryCatchTest.java:13 )
at test.TryCatchTest.main( TryCatchTest.java:7 )
NO
aaa
第三种
public class TryCatchTest {
public static void main(String[] args) {
System. out .println(fun());
}
public static String fun(){
try {
int temp =10/0;
return "abc" ;
} catch (Exception e) {
e.printStackTrace();
return "aaa" ;
} finally {
System. out .println( "NO");
return "bbb" ;
}
}
}
结果:
java.lang.ArithmeticException : / by zero
at test.TryCatchTest.fun( TryCatchTest.java:13 )
at test.TryCatchTest.main( TryCatchTest.java:7 )
NO
bbb
第三种
public class TryCatchTest {
public static void main(String[] args) {
System. out .println(fun());
}
public static String fun(){
try {
int temp =10/0;
} catch (Exception e) {
e.printStackTrace();
return "aaa" ;
} finally {
System. out .println("NO" );
}
return "bbb" ;
}
}
java.lang.ArithmeticException : / by zero
at test.TryCatchTest.fun( TryCatchTest.java:13 )
at test.TryCatchTest.main( TryCatchTest.java:7 )
NO
bbb
第四种:
public class TryCatchTest {
public static void main(String[] args) {
System. out .println(fun());
}
public static String fun(){
try {
int temp =10/0;
} catch (Exception e) {
e.printStackTrace();
} finally {
System. out .println( "NO");
return "aaa" ;
}
return "bbb" ;//这里报错
}
}
- java学习之路-------try....catch....让你想不到的结果
- Core Java学习之try,catch
- try catch 不到异常的处理
- php学习之try catch
- php学习之try catch
- php学习之try catch
- java学习--try catch finally
- java之 try catch finally
- java学习之try catch finally中的return
- java基础学习之try catch finally语句中含有return语句的执行情况
- 关于java的try-catch
- Java try . catch 的使用
- try-catch 捕捉不到异常
- try ... catch 抓不到异常
- Java基础之try 与catch的使用
- SqlServer try catch 捕获不到的一些错误及解决方法
- SqlServer try catch 捕获不到的一些错误及解决方法
- javax.mail.AuthenticationFailedException异常一个让你想不到的原因
- opencv学习-imgprocess-判断点是否在轮廓内pointPolygonTest
- 一句话
- 使用xrdp实现windows 远程桌面 ubuntu linux
- MyEclipse取消验证Js的两种途径.
- IOS学习笔记-概述
- java学习之路-------try....catch....让你想不到的结果
- "蓝屏"和"绿屏"CG技术
- 简单实用的网游服务器架构
- jquery获取控件的绝对位置
- SunOS 5.10 sparc C/C++ 初学者之动态链接库
- hdu 2084 数塔 dp
- OpenGL ES之glUniform函数
- Android 2.1下调试3G模块
- linux程序后台运行