嵌套尝试捕获不好?为什么 [英] nested try catch is not good?why

查看:70
本文介绍了嵌套尝试捕获不好?为什么的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

1)我想知道嵌套try catch不好吗?为什么?我需要理由.

2)就像我从链接中看到的那样访问它

示例 [ ]


1)I want to know that nested try catch is not good?why? i need the reason..

2) visit it also as i think from link

example[]


it could be handle by a try with multiple catches..?

推荐答案


使用白痴代码示例不能证明任何事情.对于任何有效和有用的技术,任何人都可以使用它发明完全愚蠢的代码示例,那又如何呢?

嵌套的try-catch块很重要,这可能非常有用,并且在许多情况下它们是不可避免的.此外,从这个问题来看,不清楚嵌套"是什么意思,仅仅是编码样式或功能嵌套.我的意思是,一个人可以在同一方法中使用多个嵌套的"try"语句,或者可以将一个方法的内部"try"语句执行到一个单独的方法中,这通常可以提高可读性(但这并不是必须的). br/>
现在,我不想解释使用异常的任何原因,因为它很无聊,而且很明显.如果整个方法是错误的并且问题没有道理,为什么要这样做,因为问题是基于嵌套"try-…"块很糟糕的假设.

—SA
Using an idiotic code sample does not prove anything. For any valid and useful technique anyone can invent totally idiotic code sample using it, so what?

Nested try-catch blocks are important, that can be very useful, and there are many cases when they are just unavoidable. Besides, from the question, its not clear what do you mean by "nesting", just coding style or functional nesting. I mean, one can use several nested "try" statements in the same method, or inner "try" statements can be carried out of one method into a separate method, which usually improve readability (but even that is not a must).

Now, I don''t want to explain any reasons for exception uses, because it''s boring and very obvious thing. Why doing that if the whole approach is wrong and the question makes no sense, because the question is based on the assumption that nesting "try-…" blocks are bad.

—SA


这篇关于嵌套尝试捕获不好?为什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆