I want to see exception detail in visual studio debugger without assigning variable to exception. Currently I have to write something like this:
try
{
//some code
}
catch (SecurityException ex)
{
//some code or ever no any code
}
Visual studio throws an error indicating that ex variable is never used, but i need this variable to see exception detail while debugging.
UPDATE: I know how to suppress VS error 'variable is never used', problem is in seeing exception inside watch without this variable. $exception variable by @VladimirFrolov or exception helper by @MarcGravell is an answer.
just write
You can see your exception in Locals list or use
$exception
in Watch list:use
or
but i think this is what you mean
You can use a functionality from Visual Studio.
Debug => Exceptions => Check "Common Language Runtime Exceptions"
That's it. Hope it helps.
You don't need to do anything: just put a breakpoint inside the
catch
(or on acatch
and step once into the block) and you should see an invitation to see the exception helper. This works for nakedcatch
or for type-specificcatch(SecurityException)
blocks:which gives you everything:
To avoid getting the warning: "The variable 'ex' is declared but never used" in a catch statement,do the following:
Or use System.Diagnostics.Debug.WriteLine() or Enable tracing or debugging to use a trace listener.