VS10 开发人员如何(实际使用 ReSharper 等工具)找到“不安全”方法调用 - 即调用,调用堆栈无法在没有一个安全 block (try-catch)中实现?
class A
{
public static vois f()
{
try
{
...
B.DoSome(); // safe call, exceptions handled
}
catch(Exception e)
{
...
}
}
public static void f2()
{
... //no try-catch block
B.DoSome(); // possible unhandled exception
}
}
class B
{
public static void DoSome()
{
...
//no try-catch block, possible to raise unhandled exception
}
}
最佳答案
假设您想确保您的应用程序不会因未处理的异常而崩溃,这可以通过订阅 UnhandledException
轻松完成。 AppDomain
的事件。
注:请 don't put a try-catch in every method 正如您的样本所建议的那样。
关于C#:分析 "unsafe"方法调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3846906/