View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Geoff Geoff is offline
external usenet poster
 
Posts: 371
Default Error Handling construct

I am clear about sub procs. But my post includes an On Error Resume Next and
On Error GoTo 0 around the Find statement. Resume Next permits a 'no find'
but also disables myErrorHandler? Therefore instead of Return to 0 I should
reinstate myErrorHandler?

Geoff

"Bob Phillips" wrote:

There is no need to reset the error handlers on return from a sub-procedure.
If the sub-procedure has its own error handler, it will deal with its own
errors and the error handler is cleared on exit. If the sub-procedure does
not have its own error handler, the error will be handled by the currently
active error handler, i.e the last invoked error handler in a procedure in
the parent hierarchy.

--
---
HTH

Bob


(there's no email, no snail mail, but somewhere should be gmail in my addy)



"Geoff" wrote in message
...
Hi
From tests and 'Help' it seems I need to restate On Error GoTo
myErrorHandler after returning from each sub proc and after the On Error
Resume Next.
Is that correct or is there a better way to provide error handling
throughout Main?

T.I.A.

Geoff

Sub Main()

On Error GoTo myErrorHandler

blah

SubProc1 ''no error handler in this proc

On Error Resume Next
foundIt = Sheets(1).Find("xxx", , , xlWhole)
On Error GoTo 0

SubProc2 ''no error handler in this proc

blah

Exit Sub

myErrorHandler:

If Err.Number < 0 Then
'''do something
Err.Clear
End If

End Sub