1

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
    }
}
Dirk Vollmar
  • 172,527
  • 53
  • 255
  • 316
Jamon
  • 126
  • 6

3 Answers3

3

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.

Community
  • 1
  • 1
Dirk Vollmar
  • 172,527
  • 53
  • 255
  • 316
  • 1
    +1 for the warning. The illusion of safety is worse than mere lack of safety, as at least in the latter case, you are aware of the threat. – Dan Bryant Oct 02 '10 at 19:09
  • Thanks a lot, so now I think what good way is catching UnhandledException of AppDomain. It's good way? – Jamon Oct 02 '10 at 19:20
  • 1
    @Jamon, AppDomain.UnhandledException gives you a chance to take some final action (such as logging or displaying a message box to the user) before the application shuts down. It does not give you a way to prevent the application from shutting down. It's important to have as a final catch (mainly for logging), but any exceptions you expect and know how to handle, you'll want to handle explicitly at the point where it can be thrown. – Dan Bryant Oct 02 '10 at 20:21
1

Your question is quite vague, but perhaps Exception Hunter is what you're after?

Mark Simpson
  • 23,245
  • 2
  • 44
  • 44
  • Yeah, on first look it like what I want:) Thanks. But, do you know free analogues of this stuff?) – Jamon Oct 02 '10 at 18:54
0

Here is a great microsoft tool http://stylecop.codeplex.com/.

Shawinder Sekhon
  • 1,569
  • 12
  • 23