C#: Analyze “unsafe” method invokes

烂漫一生 提交于 2019-12-11 07:07:50

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!