Page 1 of 1

Module error

Posted: Mon Nov 22, 2004 2:12 am
by Guest
Hi all

Can somebody enlighten me as to how you can enable an error handler in
multiple modules.

In the main module you can write:
On Error goto Myhandler
at the entry point into the program.

However if the other modules only contain Sub's and Functions then
placing:
On Error goto Handler2
before the subs, means the handler never gets enabled and the error
get's trapped back in MyHandler in the main module.

Yet the help files refer to Module Level Error Handlers.(as in plural)
I have tried calling a sub in Module2

SUB ERRMOD2
ON ERROR GOTO ERRTRAP2
EXIT SUB
ERRTRAP2:
Resume Next
END SUB

But that gives a compile error
005D 0006 ERRTRAP2:
^ Subprogram error

I don't want to use ON LOCAL ERROR as it is local only to that routine.

Any ideas appreciated

Regards

Posted: Mon Nov 22, 2004 6:09 am
by Z!re
I think the only way is to use ON LOCAL, I'm not sure though...

Posted: Mon Nov 22, 2004 3:20 pm
by {Nathan}
Easy. At the beginning of a sub, put a errorid$="drawmap" or something like that and at the beginning of your error handleing just do IF errorid$="drawmap" then print "unable to draw the screen' or ect.

Module error

Posted: Mon Nov 22, 2004 5:24 pm
by Jan van de Poll
Hi all

Sorry forgot to put my name on the previous post.

Further trial & error gave me my own solution.
the description below will send the error to the trap within it's own module
and you can then call the main ErrorHandler. Once it returns to the trap
it will Resume on the Next line in the correct module.
All without using LOCAL
'************************
MainModule
on error goto ertrap1
call SetTrap2 'enable Module2 error trapping
call SetTrap3 ' ditto
call SetTrap4 ' ditto

etc

'
' code and subs
'

errtrap1:
call errorhandler1
resume next
'************************
Module2

sub setTrap2
on error goto errtrap2
end sub

sub othersubs
end sub

errtrap2:
call errorhandler1
Resume Next
'************************
Module3

etc

Hope it helps someone else trying to tidy up error handling.
All I have to do now is translate the stack so that the line that caused the
error can be identified before we do a Resume Next.

Thanks for the response.

Regards