error handling and nested subs (1 Viewer)

jamesmor

Registered User.
Local time
Yesterday, 19:46
Joined
Sep 8, 2004
Messages
126
How do you guys handle having an error in a nested sub?

What I usually do is have each sub have their own error handling that way I can have a variable that tells me where the error happened and use a global error handling routine, which when it's done running it closes access.

My current employer doesn't want access to close when an error occurs, so that kind of puts me in a bind.

Below is my "template" sub

Code:
Sub SandboxMod()
If blnErrHandle Then On Error GoTo errHandler
    PushCallStack "SandboxMod"
    
    'Declarations
    
    'Initializations
    
    '<Code Entry>

exitsub:
    
    PopCallStack
    Exit Sub
    
errHandler:
    'Updating error log with information
    errorHandling
    GoTo exitsub
    
End Sub

now when it's the top sub, no problem. but when it's nested how do I get the calling sub to stop processing?

I've thought about using "End" but I've heard that leaves bits and pieces behind.

I've also thought about just letting the error bubble up. However I am afraid of what would happen to my call stack as my assumption is that if I took out the error handling part in the nested sub my exit sub code would be skipped and the calling sub's entry in the call stack wouldn't be removed.

I'm sure it's something simple that I'm overlooking.

Thanks for all your help.
 
Last edited:

pbaldy

Wino Moderator
Staff member
Local time
Yesterday, 17:46
Joined
Aug 30, 2003
Messages
36,118
One way would be to change the Sub to a Function and have it return a Boolean. In the calling sub, you test the return value and react accordingly, like:

If (GetData(Me.txtReqDate)) Then

which is a function that takes a parameter obviously. If it was successful, it returns True, otherwise False.
 

jamesmor

Registered User.
Local time
Yesterday, 19:46
Joined
Sep 8, 2004
Messages
126
there's that simple answer that I overlooked.

Thanks!
 

pbaldy

Wino Moderator
Staff member
Local time
Yesterday, 17:46
Joined
Aug 30, 2003
Messages
36,118
Happy to help!
 

Users who are viewing this thread

Top Bottom