社区
非技术区
帖子详情
catch语句中出现return;有什么结果
oceanliuyang
2006-12-10 08:23:08
public class Ceshi
{
public static void main(String args[])
{
try
{
int i=0;
if(i==0)throw new Exception();
}
catch(Exception e)
{
return;
}
System.out.println("liuhaibin");
}
}
输出结果是什么了?
...全文
208
6
打赏
收藏
catch语句中出现return;有什么结果
public class Ceshi { public static void main(String args[]) { try { int i=0; if(i==0)throw new Exception(); } catch(Exception e) { return; } System.out.println("liuhaibin"); } } 输出结果是什么了?
复制链接
扫一扫
分享
转发到动态
举报
写回复
配置赞助广告
用AI写文章
6 条
回复
切换为时间正序
请发表友善的回复…
发表回复
打赏红包
dzmonkey
2006-12-11
打赏
举报
回复
当然没有输出
不过你如果有finally的话,得先执行finally,然后才会return
zhz586
2006-12-11
打赏
举报
回复
没有输出
antwihtsea
2006-12-11
打赏
举报
回复
up
angelleecash
2006-12-11
打赏
举报
回复
catch 的语意是捕获了异常,函数体就是你处理异常的方式,你选择return,就是退出了这个异常出现的方法。
zdywqy
2006-12-11
打赏
举报
回复
jf
masse
2006-12-10
打赏
举报
回复
没有输出啊
Java的try/
cat
ch
/finally
中
使用
return
详解
finally是无论如何都要执行的,除非在try/
cat
ch
的
语句
块
中
使用的System.exit() 为了弄清楚Java
中
try/
cat
ch
/finally
中
使用
return
语句
的跳转,使用下面示例: 1. 首先在try
中
使用
return
,finally
中
不使用
return
public class App { public static void main(String[] args) throws Exception { App app = new App();
cat
ch
,finally执行遇到
return
语句
怎么办
try { //可能出异常
cat
ch
{ //try异常则执行,否则这里的代码不会执行 } finally { //不管有没有异常,finally都会执行 } 比如 public class Test { public static void main(String[] args) { //try
语句
,出错了首先执
try、
cat
ch
和finally
中
的
return
到底该怎么执行
try、
cat
ch
和finally
中
都有
return
语句
,执行哪一个
return
? 上代码解释: 第一步,
return
全开,并在try块
中
给个异常,执行结果:lastValue = finally-test;说明最终
return
的是finally块
中
的赋值; public class Try
Cat
ch
Test { public static void main(String[] args) { Try
Cat
ch
Test try
Cat
ch
Test = new Try
Cat
ch
T
finally
中
的
return
可以覆盖掉try
cat
ch
中
的
return
语句
以下代码执行的结果显示是多少()? // 以下代码执行的结果显示是多少()? public class Demo{ public static void main(String[] args){ System.out.print(getNumber(0)); System.out.print(getNumber(1)); System.out...
try
cat
ch
语句
java_深入剖析java的try…
cat
ch
…finally
语句
一、前言前些天参加面试的时候有一道题:public classtest {public static voidmain(String[] args){try{
return
;}finally{System.out.println("finally...");}}}以上程序的执行结果是什么?当时觉得finally块肯定会被执行到的,而这段程序在try块里就已经返回了,所以选了“编译
出现
错误”这个选项,...
非技术区
23,404
社区成员
70,511
社区内容
发帖
与我相关
我的任务
非技术区
Java 非技术区
复制链接
扫一扫
分享
社区描述
Java 非技术区
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
暂无公告
试试用AI创作助手写篇文章吧
+ 用AI写文章