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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to "clone" the error object?

Status
Not open for further replies.

patrickdrd

Programmer
Nov 21, 2003
149
GR
Hello everyone!
I need a way to "clone" (copy) the error object in order to prevent it from the code that's inside the error handler, i.e. so that it isn't reset,
if the code inside, has routines that have error handling themselves.

For example, consider the following code:

Code:
Option Explicit

Private Sub Form_Load()

  On Error GoTo Form_Load_Error

  Err.Raise 999

Exit Sub
Form_Load_Error:
  ' "clone" it somehow here, before test1, which resets it
  
  test1
  
  If InStr(Err.Source, " of ") = 0 Then Err.Source = "Form_Load of Form Form1"
  MsgBox CStr(Err.Number) & "~" & Err.Description

End Sub

Private Sub test1()

  On Error GoTo test1_Error

  Err.Raise 1000

Exit Sub
test1_Error:

End Sub

I would like the msgbox to contain err.number 999, not 1000!

I have in mind that it could be done using variables,
storing original err.number, err.description, etc.
and then showing them, but I'm looking for a more efficient way.
Is there one?
I do not want to fill my code with all these variables for error handling.
I cannot use set a = err,
because a would be only an instance of err,
when err is reset, a is reset as well.

I wish err had a clone method (like recordsets)!

Thanks in advance!
 
I don't think there's anything wrong with just copying the err properties to variables. That's what I usually do.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top