如果我有一个检查其参数有效性的方法,是否可以抛出派生自 System.ArgumentException
的自定义异常?我问是因为 ArgumentException
本身是从 System.SystemException
派生的,而且我看到关于应用程序是否应该从 SystemException
派生的指南存在冲突。 (尽管是间接的,从 ArgumentException
派生仍然等同于从 SystemException
派生。)
我看到很多指南说不要派生自 ApplicationException
,而是派生自 Exception。我对此很满意。我不确定是否也可以从 SystemException 派生。
如果我不应该从 SystemException
派生,那么我应该从什么派生我的 "invalid argument"
异常类?
最佳答案
MSDN page about Best Practices for Handling Exceptions说
Throw an ArgumentException or a class derived from ArgumentException if invalid parameters are passed.
所以我会说它没问题,甚至值得推荐。
关于c# - 可以从 System.ArgumentException 派生吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12857708/