How to get Exception property (error code)

Good suggestion (thanks!) but no luck.
HashCode is still the only known method to make my program work.
I tested two error cases: 1. Port Not Open and 2. Timeout.
The only way to tell the difference between them is HashCode.

Here's the code I used:
Visual Basic:
 Catch exc As Exception
 Dim ExceptionType As System.Type
 ExceptionType = exc.GetType()        ' Error GetType
 strErrMsg = exc.Message.ToString   ' Text Error Message.   
 iHashCode = exc.Message.GetHashCode  ' Error HashCode 
 Console.WriteLine("TEST1 GT=" & exc.GetType().ToString() _
                & ", H=" & iHashCode & ", M=" & strErrMsg)
Here are the outputs from the two tests:
TEST1 GT=System.ApplicationException, H=-108330557, M=Please initialize and open port before using this method
TEST1 GT=System.ApplicationException, H=-1549478346, M=Read Error: Timeout error

I tested on two different machines, both Win2000 but different configurations. Identical results.
The HashCode numbers are constant, so this seems reliable.

Maybe this will remain one of those unanswered questions.
 
You have your answer there. You should be catching the ApplicationException class. Don't rely on the hashcode.
 
I don't see any answer in using GetType.
In both my test cases, exc.GetType() yielded NO distinguishing info.
It says only "System.ApplicationException"

I need to discriminate between TimeOuts and NON TimeOuts.
The only way I see to do this is through exc.Message.GetHashCode.
(or its even clumsier sibling exc.Message.ToString)

Is there something here that I'm missing? :confused:
 
Back
Top