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

Error handling problem 6

Status
Not open for further replies.

jbrowne

Programmer
Feb 1, 2000
182
IE
Hi,

I have a problem in that my application on occasion crashes out - without error handling catching the error. Obviously this looks very unprofessional to my users when it happens. On most occasions (but not always) it is a 3021 error - 'No current record'. It happens when I do a seek or a movefirst on a table which has no records or that I haven't got a hit on. In most cases in my project I try to overcome this by checking for a nomatch or by checking the recordcount property(which I've found to be buggy by the way) but every now and again there is no check or error handler and up pops the error and crash goes the system. My question is - is there a way of doing some sort of a global error trap so that I could at least pop up a better message to the user that something serious has gone wrong and to contact support instead of the application just falling over with an untrapped VB error. Up until now all my error trapping has been within the procedure itself. Is it possible to trap errors at form level or better yet at MDIForm level (I am using an MDIForm in this project and 99% of my forms would be children to this.

Any suggestions would be greatly appreciated
John B
 
I'm interested in this call stack you keep talking about 'strongm'. Can you elaborate more on the following statement - "even if it just reraises the error so that it can bubble up the call stack until it finds an error handler that will deal with it...". I am not too familiar with call stacks or bubbling up - does this mean that the error can be caught at a form level instead of a procedure level or am I off the point here?
 
As I understand it, if a routine has no error trap and the routine that calls it does, it will get trapped in the calling routine. This works however many nested calls you have so, if no error trap, it will keep going backwards until it finds one. That doesn’t mean you can do it at ‘form level’ though as there is no single routine at form level – just lots of different event handlers.
 
here's a (contrived) example:

Option Explicit

Private Sub Command1_Click()
On Error GoTo oops
Layer1
Layer2
Layer3
Exit Sub
oops:
MsgBox "Error handled in by initiating call: " & Err.Description
Resume Next
End Sub


Public Sub Layer1()
MsgBox 1 / 0 ' oops, forgot to put any error handling in this Sub...
End Sub

Public Sub Layer2()
Dim x As Integer
On Error GoTo Layer2Err

x = 65536 * 65536
Layer1

Exit Sub

Layer2Err:
' Handle overflow
If Err = 6 Then
MsgBox "Error handled in Layer2: " + Err.Description
Resume Next
Else
Err.Raise Err.Number ' bubble any unhandled error back up call stack
End If
End Sub

Public Sub Layer3()
On Error GoTo Layer3Err
Layer2
Exit Sub

Layer3Err:
If Err = 11 Then
MsgBox "Error handled in Layer3: " + Err.Description
Resume Next
Else
Err.Raise Err.Number ' bubble any unhandled error back up call stack
End If
End Sub
 
Ok, I understand now - thanks everyone for your help - it has a great help to me.

John B
 
whilst I don't wish to denigrate strongm and his (somewhat contrived) example....
wasn't this mentioned earlier?

Take Care

Matt
If at first you don't succeed, skydiving is not for you.
 
Yes - it was mentioned earlier by yourself Matt - and thanks for that - as I said I wasn't quite clear about the meaning of call stacks so I did ask again for a further explanation - as I said - I really appreciate everyone who took the time to contribute and help out on this issue - cheers guys!
 
hmm sorry for being churlish

I was having a bad day I am afraid!

Take Care

Matt
If at first you don't succeed, skydiving is not for you.
 
Hi Guys its me again,

Just an update, I have at this stage put in the error handler routine that Lplate suggested earlier and although it was a long tedious process, it is now working a treat. Again thanks to everyone who contributed to this topic. One final question now though. When the error trap routine is called now it throws up a message box telling the user that a terminal error has occured and that the application is about to close down. The message box just has an ok button which when pressed ends the application at that stage. What I would like to do now is similar to what the Microsoft products are doin at the moment ie put a "Send Error" button on the msgbox so that the error found could be sent automatically to our support desk. Firstly how would I put this button on a msgbox successfully (or do I need to call a different form instead of the msgbox to do this) and secondly, is there an ocx out there available to tie into outlook express to send off these types of mails automatically.
Again any help or suggestions would be greatly appreciated

John B
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top