Main Site Documentation

Exceptions


#1

ex.Message is too large for a character display. Is there a way to extract a code from this that allows the exception text to be found elsewhere. So the code can be shown on a character display?


#2

Scroll the line?


#3

It depends on the exception.
Some sub types have codes, like SocketException.
Many exceptions does not even have meaningful Message, as they have on Windows.


#4

Yeah I have noticed some of the exceptions in debug appear to be meaningless …

Scrolling the exception on a 2 line character display is possible I guess, but not the most practical!

I assume I cannot drill down further into the exception to specific properties but have to search the text?


#5

If you know what exceptions to expect, you can cast them to the correct type and access the properties.
If you do file IO, you get IOExceptions.
If you do networking you get SocketExceptions


#6

Is there an example of this?


#7

This has just popped up in my debug window … is this expected? Is it trying to tell me something?

GC: 65msec 639924 bytes used, 6699744 bytes available
Type 0F (STRING ): 1752 bytes
Type 11 (CLASS ): 18960 bytes
Type 12 (VALUETYPE ): 1740 bytes
Type 13 (SZARRAY ): 11760 bytes
Type 01 (BOOLEAN ): 24 bytes
Type 03 (U1 ): 1032 bytes
Type 04 (CHAR ): 1056 bytes
Type 07 (I4 ): 756 bytes
Type 0F (STRING ): 24 bytes
Type 11 (CLASS ): 8784 bytes
Type 12 (VALUETYPE ): 84 bytes
Type 15 (FREEBLOCK ): 6699744 bytes
Type 17 (ASSEMBLY ): 46272 bytes
Type 18 (WEAKCLASS ): 96 bytes
Type 19 (REFLECTION ): 168 bytes
Type 1B (DELEGATE_HEAD ): 2016 bytes
Type 1C (DELEGATELIST_HEAD ): 96 bytes
Type 1D (OBJECT_TO_EVENT ): 768 bytes
Type 1E (BINARY_BLOB_HEAD ): 543780 bytes
Type 1F (THREAD ): 2304 bytes
Type 20 (SUBTHREAD ): 240 bytes
Type 21 (STACK_FRAME ): 3312 bytes
Type 22 (TIMER_HEAD ): 720 bytes
Type 27 (FINALIZER_HEAD ): 456 bytes
Type 31 (IO_PORT ): 540 bytes
Type 33 (I2C_XACTION ): 48 bytes
Type 34 (APPDOMAIN_HEAD ): 72 bytes
Type 36 (APPDOMAIN_ASSEMBLY ): 4824 bytes


#8

you can do in catch:

try
{
...
}
catch(SocketException ex)
{
  display = ex.ErrorCode.ToString();
}
catch(Exception ex)
{
  display =  ex.Message;
}

or via cast

var ex = ...
var socketEx = ex as SocketException;
if(socketEx != null)
{
  display = socketEx .ErrorCode.ToString();
}
else
{
  display =  ex.Message;
}