为什么Catch(异常)几乎总是一个坏主意? [英] Why is the Catch(Exception) almost always a bad Idea?

查看:74
本文介绍了为什么Catch(异常)几乎总是一个坏主意?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么Catch(异常)几乎总是一个坏主意?

Why is the Catch(Exception) almost always a bad Idea?

推荐答案

因为当你抓住异常你应该正确处理。你不能期望在你的代码中处理各种异常。另外当您捕获所有异常时,您可能会收到一个无法处理并防止堆栈中的代码正确处理的异常。

Because when you catch exception you're supposed to handle it properly. And you cannot expect to handle all kind of exceptions in your code. Also when you catch all exceptions, you may get an exception that cannot deal with and prevent code that is upper in the stack to handle it properly.

一般主体是抓住最具体的类型可以。

The general principal is to catch the most specific type you can.

这篇关于为什么Catch(异常)几乎总是一个坏主意?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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