问题
How (actual with which instuments like ReSharper) in VS10 developer can find "unsafe" method invokes - i.e. invokes, which unattainable by call stack in no one safe 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
}
}
回答1:
Assuming you would like to make sure your application is not crashing due to an unhandled exception, this can be easily done by subscribing to the UnhandledException event of the AppDomain.
Note: Please don't put a try-catch in every method as your sample suggests.
回答2:
Your question is quite vague, but perhaps Exception Hunter is what you're after?
回答3:
Here is a great microsoft tool http://stylecop.codeplex.com/.
来源:https://stackoverflow.com/questions/3846906/c-analyze-unsafe-method-invokes