CNET中国旗舰网站
ZDNet China
|
CNET科技资讯网
|
政府采购
|
行业网站联盟
ZDNet China 至顶网是中国最大的企业级IT资源门户
首页
网络安全
存储
服务器
软件
桌面产品
开发
企业管理
白皮书
中小企业
新闻
下载
社区
企业网
无线网
过滤防护
安全管理
网络存储
磁带库/VTL
数据保护
光存储
X86服务器
虚拟化
小型机
操作系统
数据库
中间件
协作办公
手机
笔记本
数码相机
C/S开发
web开发
移动开发
web软件
应用软件
博客
论坛
搜索
搜索
高级搜索
用户登录
用户名:
密码:
登录
新用户注册
社区首页
未证实消息
桌面产品
软件
开发
网络与安全
服务器
存储
下载
苹果爱好者
中小企业
活动专区
病毒/木马
新知天下
CWEEK专属社区
悬赏问答
游客:
注册
|
登录
|
会员
|
搜索
|
论坛设施
|
帮助
ZDNetChina中文社区
»
开发语言
»
Java技术
» 哪位高手帮我分析一下这个java程序的执行结果
C++开发常用工具荟萃
深入理解C语言指针的奥秘
Vista系统解惑要考虑的10件事
Asp.Net 学习资源列表
J2ME与Web Service的罗曼史
中间件技术的思想、概念、分类
.Net开发人员十种必备工具
用JSP 2.0开发Web应用程序
草根挑战豪门PHPer要为自己正名
高手写的php+flash多人视频聊天室
PHP程序员的优化调试技术和技巧
PHP程序员的优化调试技术和技巧
‹‹ 上一主题
|
下一主题 ››
投票
交易
悬赏
活动
打印
|
推荐
|
订阅
|
收藏
标题:
[问答]
哪位高手帮我分析一下这个java程序的执行结果
CNET开发专家团
专家组
UID 259939
精华
1
积分 53
帖子 4
威望 -2
ZD币 16 元
阅读权限 255
注册 2007-11-9
状态 离线
楼主
发表于 2008-3-21 13:31
资料
个人空间
短消息
加为好友
开发者在线
哪位高手帮我分析一下这个java程序的执行结果
程序是这样的:
<br>public class CatchWho2 {
<br> public static void main(String[] args) {
<br> try {
<br> try {
<br> throw new ArrayIndexOutOfBoundsException();
<br> }
<br> catch(ArithmeticException e) {
<br> System.out.println(
<br> "ArrayIndexOutOfBoundsException" +
<br> "/内层try-catch");
<br> }
<br>
<br> throw new ArithmeticException();
<br> }
<br> catch(ArithmeticException e) {
<br> System.out.println("发生ArithmeticException");
<br> }
<br> catch(ArrayIndexOutOfBoundsException e) {
<br> System.out.println(
<br> "ArrayIndexOutOfBoundsException" +
<br> "/外层try-catch");
<br> }
<br> }
<br>}
<br>为什么运行结果只有”ArrayIndexOutOfBoundsException/外层try-catch”这一句,而没有得到以下这一句”发生ArithmeticException”?外层try的内部,不也丢出了ArithmeticException()这个异常吗,紧接着的catch怎么没捕捉到它啊?
<br>另外,我想弄清楚try...catch嵌套中里层的try与外层的try,前面的catch和后面的catch它们的捕捉顺序关系是怎样的.大哥们,最好先帮我详细分析一下我的程序,然后再能举一些这方面的例子.
<br>再补充一下,最后两个catch调一下顺序,运行结果还是只有”ArrayIndexOutOfBoundsException/外层try-catch”这一句.以下两个改动的程序为什么都不能良好的运行呢?
<br>①public class CatchWho2 {
<br> public static void main(String[] args) {
<br> try {
<br>
<br> try {
<br> throw new ArrayIndexOutOfBoundsException();
<br> }
<br> catch(ArithmeticException e) {
<br> System.out.println(
<br> "ArrayIndexOutOfBoundsException" +
<br> "/内层try-catch");
<br> }
<br>
<br> throw new ArithmeticException();
<br> catch(ArithmeticException e) {
<br> System.out.println("发生ArithmeticException");
<br> }
<br>}
<br>
<br> catch(ArrayIndexOutOfBoundsException e) {
<br> System.out.println(
<br> "ArrayIndexOutOfBoundsException" +
<br> "/外层try-catch");
<br> }
<br>
<br>
<br> }
<br>}
<br>②public class CatchWho2 {
<br> public static void main(String[] args) {
<br> try {
<br>
<br> throw new ArrayIndexOutOfBoundsException();
<br>
<br> catch(ArithmeticException e) {
<br> System.out.println(
<br> "ArrayIndexOutOfBoundsException" +
<br> "/内层try-catch");
<br> }
<br>
<br> throw new ArithmeticException();
<br> }
<br> catch(ArithmeticException e) {
<br> System.out.println("发生ArithmeticException");
<br> }
<br> catch(ArrayIndexOutOfBoundsException e) {
<br> System.out.println(
<br> "ArrayIndexOutOfBoundsException" +
<br> "/外层try-catch");
<br> }
<br> }
<br>}
<br>小弟先对那些帮我解决问题的好心人们表示感谢啊?
这是一篇来自百度知道的问题
热点频道推荐:
C/S开发
|
数据库
|
WEB开发
|
嵌入式
|
项目管理
|
Admin
管理员
Member
UID 39783
精华
3
积分 24256
帖子 312
威望 5743
ZD币 3219 元
阅读权限 255
注册 2004-2-5
状态 离线
沙发
发表于 2008-3-21 13:31
资料
个人空间
短消息
加为好友
我怀疑你是复制的吗~?
这是一篇来自百度知道的问题
热点频道推荐:
C/S开发
|
数据库
|
WEB开发
|
嵌入式
|
项目管理
|
CNET开发专家团
专家组
UID 259939
精华
1
积分 53
帖子 4
威望 -2
ZD币 16 元
阅读权限 255
注册 2007-11-9
状态 离线
板凳
发表于 2008-3-21 13:31
资料
个人空间
短消息
加为好友
------------
这是一篇来自百度知道的问题
热点频道推荐:
C/S开发
|
数据库
|
WEB开发
|
嵌入式
|
项目管理
|
投票
交易
悬赏
活动
控制面板首页
编辑个人资料
积分交易
公众用户组
好友列表
个人空间管理
开通个人空间
基本概况
流量统计
客户软件
发帖量记录
论坛排行
主题排行
发帖排行
积分排行
在线时间
管理团队
管理统计
问卷调查
当前时区 GMT+8, 现在时间是 2009-7-4 14:52
Powered by Discuz! 5.5.0 © 2001-2007 Comsenz Inc.
Processed in 0.064447 second(s), 4/3 queries
TOP
清除 Cookies
-
联系我们
-
ZDNetChina中文社区
-
无图版