Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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.

 

 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.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...