How to Catch a Timeout Exception explicitly?

donaldc104

Freshman
Joined
Jan 4, 2003
Messages
32
I'm having trouble catching a Timeout Exception.
I can catch it generically with "Catch exc As Exception" and then identify it by its hash code, but this seems like a hack.
I've searched the docs and tried many experiments but can't find the "right" way to catch it. This is a serial port read timeout.
Can anyone help?

Here's my code.

Visual Basic:
 Try  ' Flush the COMM buffer:  Read until no more chars: timeout.  
            While (m_CommPort.Read(1) <> -1)  ' LOOP: Poll & read.  
                iChars += Chr(m_CommPort.InputStream(0)) ' Read any residue chars. 
                iCharCount += 1                          ' Count residue chars.  
                lblEmStatus.Text = "Flushed " & iCharCount & ",=<" & iChars & ">"  ' Display residue chars. 
            End While 

            ' A TimeOut exception here means "flush is completed, port is clear".-------------- 

            'Catch exc As System.IO.IOTimeoutException  '---THIS WONT COMPILE: NOT DEFINED.-- 
            'Catch exc As System.Runtime.InteropServices.IOTimeoutException  '---THIS WONT COMPILE: NOT DEFINED.-- 
            'Catch exc As System.IO.StringReader.IOTimeoutException    '---THIS WONT COMPILE: NOT DEFINED.-- 
        Catch exc As System.IO.IOException '---THIS COMPILES BUT NEVER CATCHES ANY EXCEPTIONS.-- 
            MsgBox("System.IO.IOException") 
        Catch exc As ServiceProcess.TimeoutException  '---THIS COMPILES BUT NEVER CATCHES ANY EXCEPTIONS.-- 
            MsgBox("ServiceProcess.TimeoutException") 

        Catch exc As Exception  ' THIS CATCHES ALL EXCEPTIONS OK. 
            Dim ExceptionType As System.Type 
            ExceptionType = exc.GetType() 
            strErrMsg = exc.Message.ToString ' Text Error Message.  
            iHashCode = exc.Message.GetHashCode 
            MsgBox("Generic Exception " & iHashCode & "=<" & strErrMsg & ">") ' 
            ' codes= -11889027343=NotOpen, +1218191172=Timeout 
        End Try

Where can I look up these mysterious codes ? They are not valid HRESULTS.
I need to find out the Exception Types that correspond to these codes.
 
Back
Top