$exception and $ReturnValue

In dotnet one can write

try{
    ...
}catch(Exception){
   throw;
}

which gives two debugging tools.  The first is the ability to set a break point on the catch line.

Note how I haven’t written catch( Exception exc) but only catch( Exception).  This makes us avoid a compiler warning because we don’t use the exc variable.  Which brings us to trick number two in Visual studio: Since we don’t have a variable with the exception instead write $exception in the immediate window or the quickwatch window.  $exception brings forward the [hidden] exception reference.

Also note how there is no variable behind the throw statement.  This makes the framework hide the catch/throw and leave the stack intact.

Update: In VisualStudio2010 it looks like it is enough to write exception in the quickwatch window.

With dotnet 4.5.1? one can write $ReturnValue the same way to get to the… the… the… return value!

Tags: , ,

Leave a Reply