尝试抓住开销。 [英] try catch overhead.

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

问题描述




try catch块附带了任何开销吗?在C#中,一切都是

例外。那么为每个函数设置一个try catch块是否可以?或者

还有其他任何方式。什么是正确/高效的编程

练习??

还有其他文章可用吗?


谢谢你你的时间。


问候,

Gobi。

Hi,

Is there any overhead attached with the try catch block? In C# everything is
an exception. So is it OK to have a try catch block for each function ??? or
is there any other way. What is the correct /efficient programming
practise??
Is there any other article available on the same?

Thanks for your time.

Regards,
Gobi.

推荐答案

On 6 Dez.,07:28,Gobinath, < gobinat ... @ coolgoose.comwrote:
On 6 Dez., 07:28, "Gobinath" <gobinat...@coolgoose.comwrote:




是否有任何与try catch相关的开销块?在C#中,一切都是

例外。那么为每个函数设置一个try catch块是否可以?或者

还有其他任何方式。什么是正确/高效的编程

练习??

还有其他文章可用吗?


谢谢你你的时间。


问候,

戈壁。
Hi,

Is there any overhead attached with the try catch block? In C# everything is
an exception. So is it OK to have a try catch block for each function ??? or
is there any other way. What is the correct /efficient programming
practise??
Is there any other article available on the same?

Thanks for your time.

Regards,
Gobi.



只要没有实际的异常,开销就很小。

然而,将每个函数包装成try / catch块会

有点不正统。通常你会让异常冒泡。到顶层的
全局错误处理程序,让它处理错误 -

日志记录并显示错误信息。

明显的异常来自这是当您预期某个

异常并且能够从中恢复时,那么您将在try catch中包装

最小的代码片段并且仅捕获

您知道可以从中恢复的例外情况。

如果您想了解有关例外情况的更多信息,请查看Jon

Skeet的主页,他收集了大量非常有用的文章

关于许多c#主题:
http://www.yoda.arachsys.com/csharp/exceptions2.html


hth,

Kevin Wienhold

As long as there is no actual exception, the overhead is very small.
However, wrapping every single function into a try/catch block would
be somewhat unorthodox. Normally you let exceptions "bubble up" to a
global error handler on the top level and let that handle the error-
logging and display error information.
The obvious exception from this is when you anticipate a certain
exception and are able to recover from it, then you would wrap the
smallest possible piece of code in the try catch and only catch the
exceptions that you know you can recover from.
If you want more information on exceptions you should check out Jon
Skeet''s homepage, he has a great collection of really useful articles
on many c# topics:
http://www.yoda.arachsys.com/csharp/exceptions2.html

hth,
Kevin Wienhold


来自:KWienhold [mailto:他****** @ trashmail.net]
From: KWienhold [mailto:he******@trashmail.net]

发表于:2007年12月6日星期四3:47 PM

发布到:microsoft.public.dotnet.languages.csharp

对话:尝试抓住开销。

主题:Re:尝试抓住开销。
Posted At: Thursday, 6 December 2007 3:47 PM
Posted To: microsoft.public.dotnet.languages.csharp
Conversation: try catch overhead.
Subject: Re: try catch overhead.



* snip *

*snip*


只要没有实际的异常,开销就非常小。

但是,将每个函数包装到try / catch块中会使得b $ b有点不正统。通常你会让异常冒泡。到顶层的
全局错误处理程序,让它处理错误 -

日志记录并显示错误信息。
As long as there is no actual exception, the overhead is very small.
However, wrapping every single function into a try/catch block would
be somewhat unorthodox. Normally you let exceptions "bubble up" to a
global error handler on the top level and let that handle the error-
logging and display error information.



* snip *


Hey KWien,


您提到错误 - logging是全局错误处理程序。到目前为止,观察到的所有内容都是可见的对话,并且惹恼了。

的客户,然后在打电话说出来之前关闭它

错了。


我在哪里可以找到错误日志信息?事件查看器?一个本地的

文件?在某个Windows目录下?


这对于了解客户端站点的调试非常有用

一旦他们关闭了Exception屏幕并且可以''重现

错误。


问候,

Wingot

*snip*

Hey KWien,

You mentioned error-logging be the global error handler. All I had
observed so far was the visible dialogue that comes up and "annoys" the
customer, who then proceeds to close it before calling to say something
was wrong.

Where would I find the error-log information? Event Viewer? A local
file? Within the Windows directory somewhere?

This would be very beneficial to know for debugging at the clients site
once they have closed the Exception screen and can''t reproduce the
error.

Regards,
Wingot


Gobinath ......好吧,不是_everything_是一个例外,因为C#支持

Try,

out模式,如Double.TryParse:)


问候,

杰夫


***通过Developersdex发送 http://www.developersdex.com ***
Gobinath... Well, not _everything_ is an exception as C# does support
the Try,
out pattern as in Double.TryParse :)

Regards,
Jeff

*** Sent via Developersdex http://www.developersdex.com ***


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

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