C# Noob - Exception Handled but not available

  • Thread starter Thread starter Richard Coltrane
  • Start date Start date
R

Richard Coltrane

Hello,

Im reasonably new to C#. Im catching an exception of type WebException as
below:

catch (WebException ex)
{
link.LinkState = (short)(LinkState.Stored);
Debug.WriteLine(ex.Message);
}

The first line in this catch block is hit and executes but the second is
just lpain ignored. When i opened the immediate window and tried a

?ex.Message
i get

?ex.Message
The name 'ex' does not exist in the current context

when i then pull up locals view and i see that the exception var has been
renamed to - $exception?

I dont understand whats going on here. Does this mean i cant log the
exception? I guess not if i cant even access it.

Thanks

Richard
 
Hello,

Im reasonably new to C#. Im catching an exception of type WebException as
below:

catch (WebException ex)
{
link.LinkState = (short)(LinkState.Stored);
Debug.WriteLine(ex.Message);

}

The first line in this catch block is hit and executes but the second is
just lpain ignored. When i opened the immediate window and tried a

?ex.Message
i get

?ex.Message
The name 'ex' does not exist in the current context

when i then pull up locals view and i see that the exception var has been
renamed to - $exception?

I dont understand whats going on here. Does this mean i cant log the
exception? I guess not if i cant even access it.

Thanks

Richard

If you've stepped over the line you might be out of scope, just drag
the current line indicator back up onto the debug.print line and you
should be able to see ex again.
 
Hello,

Im reasonably new to C#. Im catching an exception of type WebException as
below:

catch (WebException ex)
{
link.LinkState = (short)(LinkState.Stored);
Debug.WriteLine(ex.Message);
}

The first line in this catch block is hit and executes but the second is
just lpain ignored.
Debug.WriteLine writes to the elements in the Debug.Listeners
collection. Unless you have explicitly added your destination of
choice you will not see any output. Quoting from the MS Help: "To
redirect output to the console window, add an instance of the
ConsoleTraceListener. To redirect output to a file or stream, add an
instance of the TextWriterTraceListener."

rossum
 
Back
Top