ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Error Handling question (https://www.excelbanter.com/excel-programming/391869-error-handling-question.html)

J@Y

Error Handling question
 
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?

Tom Ogilvy

Error Handling question
 
On error goto ErrorHand '<-- remove colon here
code 1...
code 1...
code 1...
On error goto 0

Exit Sub
ErrorHand: '<-- keep colon here
code...

--
Regards,
Tom Ogilvy


"J@Y" wrote:

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?


Dave Peterson

Error Handling question
 
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.


J@Y wrote:

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?


--

Dave Peterson

Chip Pearson

Error Handling question
 
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)



"Dave Peterson" wrote in message
...
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.


J@Y wrote:

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?


--

Dave Peterson




All times are GMT +1. The time now is 05:30 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com