为什么好的程序员有时会默默地吞下异常? [英] Why do good programmers sometimes silently swallow exceptions?

查看:65
本文介绍了为什么好的程序员有时会默默地吞下异常?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道这很邪恶,但是我已经看到了优秀程序员编写的代码中的吞噬异常.因此,我想知道这种不良做法是否至少可以带来一个积极的方面.

I know it's evil, but I've seen swallowed exceptions in code written by a good programmer. So I'm wondering if this bad practice could have at least one positive point.

换句话说,这很糟糕,但是为什么好的程序员在稀有场合会使用它呢?

In other words, it is bad but why do good programmers, on rare occasions, use it?

try
{
    //Some code
}
catch(Exception){}

推荐答案

在我自己的代码中,我在日志记录代码中找到了一个位置,该位置在无法写入文件和未能写入事件日志之后,吞下该错误,因为没有地方可以报告它了.那是一个例子:没有很多其他的例子.

Looking in my own code, I found a place in my logging code where, after failing to write to a file and failing to write to the event log, it swallows the error as there is no place left to report it. That's one example: there aren't many others.

这篇关于为什么好的程序员有时会默默地吞下异常?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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