这可能是个愚蠢的问题,但我想知道我的代码在编程上是否正确。
private void Connect()
{
try
{
// I will do something here
}
catch(Exception ex)
{
// If something bad happened
// I want to ignore the problem and continue the execution
// So, nothing will be placed in the catch block
}
}
提前致谢。
最佳答案
好吧,您的代码准确地描述了您的评论。但是,如果连接失败,继续就好像什么也没发生一样,这听起来是一个非常糟糕的主意。你要连接什么?你有什么机会真的能够继续成功?您甚至不想记录错误吗?您真的要捕获所有 异常而不是只捕获特定异常吗?
关于c# - 异常处理 C#,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6665833/