【发布时间】:2011-05-23 21:12:51
【问题描述】:
我有一些代码会引发如下异常。
if (jobFinished)
{
...
} else
{
throw new Exception("The server Error ...")
}
它编译/运行没有问题,但是当我运行 StyleCop 时,我收到一条错误消息,指出异常不是特定的。
Error 10 CA2201 : Microsoft.Usage : Function(string, DirectoryInfo, string, string, string, out string)'
creates an exception of type 'Exception', an exception type that is not sufficiently
specific and should never be raised by user code. If this exception instance might be
thrown, use a different exception type.
我只是想在遇到一些错误情况时抛出一个错误。我怎样才能做出足够具体的例外?
【问题讨论】:
标签: c# visual-studio-2010 stylecop