有时候我有时会吸收我的例外吗? [英] Is it okay that I sometimes sink my exceptions?

查看:139
本文介绍了有时候我有时会吸收我的例外吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个最佳实践的问题。我意识到这是主观的,但是如果这是一个常见的编程习惯,想要比我更智能的人。



如果你有一种非关键的方法,不想干扰你的应用程序的重要功能,常见的是使用这样的错误接收器?

 尝试
'做东西不重要,如果失败。

捕获ex作为例外
'sink。没做什么。
结束尝试

如果你在想招聘我,你正在阅读我的一些代码看到这个...你会吗?



Seth



编辑
哇!感谢您的答案。我认为共识是永远不应该做,或者应该是非常罕见的。



我以为我会给你这个问题的上下文。首先,我对Karl Sequin的文章非常熟悉,多年来一直遵循这种模式。



但是今天在我正在开展的项目中,我正在通过变更清单进行工作,并且面临着增加一个简单的功能。 (如果您想知道...正在为Rich Text Box添加上下文菜单支持。)



附注说,如果需要超过15分钟...算了吧。



所以我面对添加什么是一个潜在有用的功能,但是没有时间来测试它不会破坏工作功能。为了记录,我们的这个系统的异常处理程序有一个机制来处理和下沉或记录这些错误。但是,如果我在一个没有强大的错误处理系统的系统上工作,该怎么办?是否可以添加此功能,如果发生错误...没有什么是真正的迷失。



这是我的想法。但是我已经把你的信息放在心上,基本上这是一个坏主意。



Seth

解决方案

是的,这是常见的,但一般来说不应该这样做。



有一些例外,如 OutOfMemoryException 哪些最好没有被捕获,除非你抓住他们试图优雅地终止你的应用程序。在大多数情况下,吞下 System.Exception System.SystemException



将不可避免地隐藏运行时问题。


I have a best practices question. I realize this is subjective but wanted to ask people smarter than me if this is a common programming practice.

If you have a method of something NON-CRITICAL that you don't want to interfere with the important functioning of your application, is it common to use an error sink like this?

Try 
    'do stuff.  not important if it fails.

Catch ex as exception
    'sink.  do nothing.
End Try

If you were thinking of hiring me and you were reading some of my code and saw this...would you?

Seth

EDIT Wow! Thanks for your answers. I think the consensus is that should never be done or it should be very rare.

I thought I would give you context for this question. First, I have a strong familiarity with the Karl Sequin article and have followed that pattern for years.

But today on the project I was working on, I was working through the change list and was faced with the addition of a simple feature. (If you care to know...it is adding context menu support to a Rich Text Box.)

The attached note said, "if it takes longer than 15 mins...drop it."

So I am faced with adding what is a potentially useful feature but the don't really have the time to test that it won't break working features. For the record, our exception handler for this system DOES have a mechanism for handling and sinking or logging these errors. But what if I was working on a system that did not have a robust error handling system. Would it be okay to add this feature and if an error occurs...nothing is really lost.

That was my thinking. But I have taken your message to heart...that basically this is a bad idea.

Seth

解决方案

Yes, it is common, but in general it shouldn't be done.

There are exceptions like OutOfMemoryException which are better not caught, unless you catch them to attempt to terminate your application gracefully.

In the majority of cases, swallowing System.Exception or System.SystemException will inevitably hide further run-time problems.

这篇关于有时候我有时会吸收我的例外吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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