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

Problems with Nested Error Handlers

Status
Not open for further replies.

TrekFan

Programmer
Apr 23, 2003
25
CR
Hi there ,

I have problems with the behavior on some nested error handling procedures ! In case of an error, I would like to active the current’s procedure error handler, do some clean up code for that procedure, and return control to the parent’s procedure error handler and so on …

Let ‘s say we have the following code :

Sub Main()
On Error GoTo Err_Gen
...
Call Procedure A
...
GoTo EndProc
Err_Gen:
Err.Raise Err.Number, ".ReadIniFile: ", Err.Description

On Error GoTo 0
EndProc:

End Sub

-----------------
Sub A()
On Error GoTo Err_Gen

….
Call Procedure B

GoTo EndProc
Err_Gen:
Clean up code for Procedure A
Err.Raise Err.Number, ". Procedure A: ", Err.Description

On Error GoTo 0
EndProc:

End Sub

-----------------
Sub B()
On Error GoTo Err_Gen

….error happens here ...

GoTo EndProc
Err_Gen:
Clean up code for Procedure B
Err.Raise Err.Number, ". Procedure B: ", Err.Description

On Error GoTo 0
EndProc:

End Sub


The idea is that if an error occurs on Procedure B, it would activate B’s error handler, do some clean up code specific for that Procedure, and then pass control the procedure’s A error handler and so on. The problem is that ‘s procedure B is trying to dispay the error msg box …

Any ideas would be really appreciate it !!


Thanks


TrekFan


PS. By the way the procedures of the examples are implemented on different classes in different objects.


 
You should do a search on error handler, this has recently been discussed in detail. In thread222-724211 strongm gives a good example to help in understanding the process.

"Two strings walk into a bar. The first string says to the bartender: 'Bartender, I'll have a beer. u.5n$x5t?*&4ru!2[sACC~ErJ'. The second string says: 'Pardon my friend, he isn't NULL terminated'."
 
Dr JavaJoe,

Thanks for your response. I did check it out but still that didn't help me.

I would like to document this in case it helps someone. What was happening is that the err structure was loosing its values !!!

This means that i had a code that said :

Err_Gen:
[More Code here]

Err.Raise Err.Number, ".ReadIniFile: ", Err.Description

On Error GoTo 0
...

what I had to do was to save the values of the object err in temporary variables and the problem was fixed ...

That is,

Err_Gen:
lErrNum = Err.Num
lErrDesc = Err.Description

[More Code here]
Err.Raise lErrNum , ".ReadIniFile: ", lErrDesc

On Error GoTo 0
...


Thanks !!


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top