C#:应该所有的异常被捕获 [英] C#: should all exceptions be caught

查看:111
本文介绍了C#:应该所有的异常被捕获的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果所有的异常可以在C#程序捕获,或者有一些例外(如堆栈溢出,内存等)的,你应该让程序崩溃,因为没有办法从他们恢复<? / p>

解决方案

您应该只抓到,你是能够处理异常。决不曾经捕获异常,什么也不做。尽最大努力保持异常从未然。因为异常产生性能上的惩罚,由于堆栈跟踪这是在.net中尤其重要。


Should all exceptions be caught in a C# program, or are some exceptions (such as stack overflow, out of memory etc.) ones that you should allow the program to crash on because there is no way to recover from them?

解决方案

You should only catch exceptions that you are able to handle. Never ever catch exceptions and do nothing. Do your best to keep the exception from occurring in the first place. This is especially important in .Net because exceptions incur a penalty in performance due to the stack trace.

这篇关于C#:应该所有的异常被捕获的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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