gpt4 book ai didi

c# - System.Exception 或只是 Exception

转载 作者:行者123 更新时间:2023-11-30 13:17:55 24 4
gpt4 key购买 nike

我是一名编程初学者,老实说,我想确保我所学的一切都是正确的。我的问题是,在 MSDN 站点上,它说明了在处理异常时我必须使用“System.foo”,例如:

catch (System.DllNotFoundException ex)

但是我周围的很多程序员都倾向于使用没有标题的异常,例如:

catch  (DllNotFoundException ex)

我知道这可能是微不足道的,也许我问这个问题很愚蠢,但这两种实现有什么真正的区别吗?比如这两者中哪一个更好?

我很感激任何建议,

提前致谢。

最佳答案

using System;
using System.IO;

...
catch (DllNotFoundException)
{
}
catch (IOException)
{
}

// not using that namespaces

...
catch (System.DllNotFoundException)
{
}
catch (System.IO.IOException)
{
}

所以没有区别。仅取决于您导入的确切命名空间。

关于c# - System.Exception 或只是 Exception,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5523662/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com