views:

71

answers:

2

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
    }
}
+3  A: 

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.

0xA3
+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
Thanks a lot, so now I think what good way is catching UnhandledException of AppDomain. It's good way?
Jamon
@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
+1  A: 

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

Mark Simpson
Yeah, on first look it like what I want:) Thanks. But, do you know free analogues of this stuff?)
Jamon
I'm not aware of any, sorry
Mark Simpson