Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Exception Handling

Status
Not open for further replies.

lsmyth1717

Programmer
Mar 25, 2005
44
GB
Does anyone know how to do exception handling in vb6. Do you use the Try Catch blocks. If so can someone show me a very quick example of this
 
There are no try/catch blocks in VB. I wish there was. VB.Net has them.

In VB, you use On Error. There are several ways to use it.

On Error Resume Next ' This will ignore errors and continue

On Error Goto LineLabel ' This will jump you to error handler

On Error Goto 0 ' This will turn off error handling

The best way (in my opinion) to use error handling is....

Code:
Public Sub ErrorHandlingExample()
  On Error Goto ErrorHandler

  Dim iTest as Integer

  iTest = iTest / 0

  Exit Sub

ErrorHandler:

  Call MsgBox(Err.Description)

End Sub

This is a brief description, you should look at the help files more a fuller understanding of error handling.

-George

Strong and bitter words indicate a weak cause. - Fortune cookie wisdom
 
You might also check out the FAQ section of the forum, for example faq222-1694

________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

'If we're supposed to work in Hex, why have we only got A fingers?'

Essex Steam UK for steam enthusiasts
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top