|
-
Jan 28th, 2003, 05:26 PM
#1
Thread Starter
New Member
Error Handling problem - code example
I maintain a rather complex vb app, and I'm trying to rework how certain errors are handled.. Heres the situation: FormA.call1() calls FormB.call2() which calls FormB.call3() all of which have on error clauses... when an error occurs in FormB.call3() our error handler gets called and does some work to recover from the error and gets the application back to a usable state.
The problem is that once the error handling is complete FormB.call3() exits and I pick up where I left off in FormB.call2(). Which is not what I want to do. I'd really like to just drop everything in the call stack. (directly exit all active methods) Since I dont think thats possible, I attempted to raise another error in the FormB.call3() error clause which kicks me back up to FormB.call2()'s error clause. But I'm unable to keep this up... if I raise another error in an attempt to get me back to FormA.call1()'s error clause, I get a runtime error.
Any suggestions?
heres a code example:
FormA
Public sub call1()
on error goto call1_err
:
call FormB.call2()
:
call1_err:
exit sub
end sub
FormB
Public sub call2()
on error goto call2_err
:
call FormB.call3()
:
call2_err:
call errorHandler(err)
err.raise 1600
end sub
FormB
Public sub call3()
on error goto call3_err
:
*** throws an error ****
:
call3_err:
call errorHandler(err)
err.raise 1600
end sub
the errorhandler would check for err#1600 and do nothing for thiese cases...
Any suggestions would be welcome.
Thanks,
-
Jan 28th, 2003, 05:46 PM
#2
I'm not sure if this is what you are after.
FormA
VB Code:
Option Explicit
Public Sub call1()
On Error GoTo call1_err
Call FormB.call2
Exit Sub
call1_err:
MsgBox Err.Number
End Sub
Private Sub Command1_Click()
call1
End Sub
FormB
VB Code:
Option Explicit
Public Sub call2()
On Error GoTo call2_err
Call FormB.call3
call2_err:
If Err.Number = 1600 Then
Err.Number = 0
Err.Raise 1600
End If
End Sub
Public Sub call3()
Dim i As Integer
On Error GoTo call3_err
i = 5 / 1
call3_err:
' Call errorHandler(Err)
Err.Raise 1600
End Sub
-
Jan 28th, 2003, 05:58 PM
#3
Thread Starter
New Member
hmm
That looks pretty much like what I have... other than resetting the err.number to 0 before raising the error again.. One thing that came to mind that I have'nt had a chance to test yet is that I have the 'Break in Class Module' selected under Tools->Options->general in the error trapping settings... would that cause it to break in the formB.call2() error clause? before heading back to formA.call1() error clause?
-
Jan 29th, 2003, 09:56 AM
#4
Thread Starter
New Member
Resolved..
Well, that was my problem. I changed the error trapping setting to be break on unhandled errors and now it works fine.. Thanks for looking at this..
-
Jan 29th, 2003, 10:49 AM
#5
WhynothavetheSubCall1asabooleanfunction,thenifanerrorisraisedsetthefunctiontoFalse...
-
Jan 29th, 2003, 11:54 AM
#6
Thread Starter
New Member
Because then I have to check for return values on every method call that has error handling, and if I raise an event that has error handling I wont have that as an option, besides with 10,000 plus lines of code I'd really hate to go back and do that. 
Due to the nature of my application when an error occurs I need to get completely out of the current line of processing and I never want to continue on. But I dont want to close the app either. So the method I've chosen allows me to exit all of the active methods without actually executing any more of the code in them.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|