Visual Studio Tips

Jeremy Hutchinson listed out series of tips to be more productive in Visual Studio.

I was not aware of tip #2 - $exception Pseudovariable - Viewing uncaptured exception while debugging. Visual studio has a pseudo variable $exception in the debug mode which will hold the details of the last exception. To explore $exception, let’s create a small project:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
static void Main(string[] args)
{
    Object foo = null;

    string bar;
    try
    {
        bar = foo.ToString();
    }
    catch (Exception)
    {
        // Oh! What cause this exception?
        bar = null;
    }
}

Put a breakpoint at line 13 and run above code. The code will throw an exception and pause the execution in catch block. Now here you can use $exception variable to inspect exception details.

Visual Studio - $exception variable

Visual Studio - $exception variable

0 Comments