是否有一个情况,当它是适合使用空的catch块?它是、有一个、适合、情况

2023-09-04 07:28:01 作者:纸飞机ペ载走童年の梦

可能显示的文件:   为什么是空的catch块一个坏主意?   Is那里曾经忽略捕获的异常

任何有效的理由

你知道任何情况下,当一个空的catch块不是绝对的邪恶?

 尝试
{
    ...
    //什么和何时?
    ...
}
抓住 { }
 

解决方案

有很多关于这个问题,尝试看看:

父母别用这样东西当奖励,可能是 毁娃神器 ,家里再有钱也不行

为什么是空的catch块一个坏主意?

这是该职位的接受的答案:

  

通常是空的try-catch是一个糟糕的主意,因为你是默默吞咽错误状态,然后继续执行。有时这可能是正确的事情,但通常这是一个开发者看到了一个异常的迹象,不知道该怎么办才好,所以用一个空的catch沉默的问题。

     

这是编程相当于把黑色胶带封住发动机警告灯。

Possible Duplicates: Why are empty catch blocks a bad idea? Is there any valid reason to ever ignore a caught exception

Do you know any situations when an empty catch block is not the absolute evil?

try
{
    ...
    // What and When?
    ...
}
catch { }

解决方案

There are a lot of questions on this, try to look at:

Why are empty catch blocks a bad idea?

From that post's accepted answer:

Usually empty try-catch is a bad idea because you are silently swallowing an error condition and then continuing execution. Occasionally this may be the right thing to do, but often it's a sign that a developer saw an exception, didn't know what to do about it, and so used an empty catch to silence the problem.

It's the programming equivalent of putting black tape over an engine warning light.

 
精彩推荐
图片推荐