尝试渔获物 [英] try-catches

查看:104
本文介绍了尝试渔获物的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

try-catches主要用于代码,这些代码可能会产生

运行时错误,例如除零或字母A。一个

整数。


有人说我们可以在某种情况下使用try-catch,但是因为没有

可能运行 - 时间错误涉及,我使用if-else语句

代替。


-
http://mysite.verizon.net/vze8adrh/news.html (个人资料)--Tim923我的电子邮件是有效的。

Are try-catches mainly just used for code that could generate a
run-time error like division-by-zero, or the letter "A" for an
integer.

Someone said we could use try-catch in a situation, but since no
possible run-time error was involved, I used if-else statements
instead.

-
http://mysite.verizon.net/vze8adrh/news.html (profile) --Tim923 My email is valid.

推荐答案

你好蒂姆,


是的尝试Catch被邮件用于代码,可能会产生一些

异常并且我们可以捕获该异常并且可以采取适当的操作,因此

应用程序不会崩溃或意外行为。


有时用户会在

应用程序中为某些条件抛出自定义异常。


Manish

Tim923写道:
Hi Tim,

Yes Try Catch are mailly used for code that probably can generate some
exception and we can catch that exception and can take appropriate action, so
that application will not crash or behave unexpectedly.

Some times user throws his custom exceptions for some conditions in
application.

Manish
"Tim923" wrote:
try-catches主要用于可能产生运行时错误的代码,例如除零或字母A。一个
整数。

有人说我们可以在某种情况下使用try-catch,但由于没有涉及可能的运行时错误,我使用了if-else语句<相反。

-
http://mysite.verizon.net/vze8adrh/news.html (个人资料)--Tim923我的电子邮件是有效的。
Are try-catches mainly just used for code that could generate a
run-time error like division-by-zero, or the letter "A" for an
integer.

Someone said we could use try-catch in a situation, but since no
possible run-time error was involved, I used if-else statements
instead.

-
http://mysite.verizon.net/vze8adrh/news.html (profile) --Tim923 My email is valid.





" Tim923" <菊******** @ verizon.net>在留言中写道

news:0u ******************************** @ 4ax.com ...

"Tim923" <ju********@verizon.net> wrote in message
news:0u********************************@4ax.com...
try-catches主要用于可能产生运行时错误的代码,例如除零,或字母A。一个
整数。

有人说我们可以在某种情况下使用try-catch,但由于没有涉及可能的运行时错误,我使用了if-else语句<相反。
Are try-catches mainly just used for code that could generate a
run-time error like division-by-zero, or the letter "A" for an
integer.

Someone said we could use try-catch in a situation, but since no
possible run-time error was involved, I used if-else statements
instead.




如果可能的话,最好避免使用try catch,因为

异常是相当耗费资源的。


Michael Culley



It''s probably better to avoid using try catch if possible because an
exception is fairly resource intensive.

Michael Culley


尝试/捕获用于处理您预期可能发生的情况但是

不一定能避免。如果你试图打开一个数据库连接,服务器可能会被关闭 - 所以你可能想要抓住它并将这些东西写入队列,这样你就可以获得
了后来。但是你不应该使用try / catch来代替

适当地检查前置条件。捕捉异常并不便宜

所以如果你可以使用IF声明来避免它们,那么一定要这样做。


Jon Skeet有一个很好的在他的网站上对此进行分析......让我看看我是否可以找到这个链接。


-

WG Ryan MVP(Windows Embedded)

TiBA解决方案
www.tibasolutions.com | www.devbuzz.com | www.knowdotnet.com

" Tim923" <菊******** @ verizon.net>在留言中写道

news:0u ******************************** @ 4ax.com ...
Try/catches are used to handle situations that you expect could happen but
can''t necessarily avoid. If you try to open a db connection, the server may
be down - so you may want to catch it and write the stuff to a queue so you
can get it later. However you shouldn''t use try/catching in place of
checking for preconditions appropriately. Catching exceptions isn''t cheap
so if you can use an IF statement to avoid them, by all means do it.

Jon Skeet has an excellent analysis of this on his site...let me see if I
can find the link.

--
W.G. Ryan MVP (Windows Embedded)

TiBA Solutions
www.tibasolutions.com | www.devbuzz.com | www.knowdotnet.com
"Tim923" <ju********@verizon.net> wrote in message
news:0u********************************@4ax.com...
try-catches主要用于可能产生运行时错误的代码,例如除零,或字母A。一个
整数。

有人说我们可以在某种情况下使用try-catch,但由于没有涉及可能的运行时错误,我使用了if-else语句<相反。

-
http://mysite.verizon.net/vze8adrh/news.html (个人资料)--Tim923我的电子邮件
Are try-catches mainly just used for code that could generate a
run-time error like division-by-zero, or the letter "A" for an
integer.

Someone said we could use try-catch in a situation, but since no
possible run-time error was involved, I used if-else statements
instead.

-
http://mysite.verizon.net/vze8adrh/news.html (profile) --Tim923 My email



有效。


is valid.


这篇关于尝试渔获物的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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