Error Handling question

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have this set of code:

On error goto ErrorHand:
code 1...
code 1...
code 1...
On error goto 0

ErrorHand:
code...

Somewhere within the Code 1, there is a type mismatch error, but the program
doesn't go to ErrorHand, instead it goes debug window. Am I doing something
wrong?
 
On error goto ErrorHand '<-- remove colon here
code 1...
code 1...
code 1...
On error goto 0

Exit Sub
ErrorHand: '<-- keep colon here
code...
 
Inside the VBE, try:

Tools|Options|General Tab|Error Trapping Section
What's checked?
I'm guessing "break on all errors"

Try changing that to "break on unhandled errors"

If I did this in a General module:

Option Explicit
Sub testme()

On Error GoTo ErrorHand:
Err.Raise 33
On Error GoTo 0

Exit Sub

ErrorHand:
MsgBox Err.Number
Resume Next
End Sub

I'd get the debug window only if "break on all errors" was checked.
 
Try changing that to "break on unhandled errors"

In general, it is better to use "Break In Class Module" rather than "Break
On Unhandled Errors". With break in class module, you'll enter debug mode on
the exact line within a class that caused the problem. With break on
unhandled errors, you'll break on the code that called the method of the
class, which is of little use for debugging. Of course, this is irrelevant
if you don't have code in any classes.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting
www.cpearson.com
(email on the web site)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top