我目前正在编写一个小框架,将由公司内部的其他开发人员在内部使用.
我想提供良好的Intellisense信息,但我不知道如何记录抛出的异常.
在以下示例中:
public void MyMethod1()
{
MyMethod2();
// also may throw InvalidOperationException
}
public void MyMethod2()
{
System.IO.File.Open(somepath...); // this may throw FileNotFoundException
// also may throw DivideByZeroException
}
Run Code Online (Sandbox Code Playgroud)
我知道记录异常的标记是:
/// <exception cref="SomeException">when things go wrong.</exception>
Run Code Online (Sandbox Code Playgroud)
我不明白的是如何记录被调用的 代码引发的异常MyMethod1()
?
MyMethod2()
File.Open()
吗?记录可能的异常的最佳方法是什么?
您是否知道是否有任何选项或扩展来生成捕获Visual Studio中方法抛出的所有异常所需的代码?
比如我在打电话 File.WriteAllBytes(...)
该方法可以抛出9个Exceptions:System.ArgumentException,System.ArgumentNullException等等.
我想要所有9个例外的代码:
catch (ArgumentException) {
}
catch (ArgumentNullException) {
}
...
Run Code Online (Sandbox Code Playgroud)
我在Eclipse for Java中看到过这种行为,但我想知道Visual Studio中是否有类似的东西.
顺便说一下,我正在使用Visual Studio 2012 Premium