Module error

If you have questions about any aspect of QBasic programming, or would like to help fellow programmers solve their problems, check out this board!

Moderators: Pete, Mods

Post Reply
Guest

Module error

Post 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
Z!re
Veteran
Posts: 887
Joined: Wed Aug 04, 2004 11:15 am

Post by Z!re »

I think the only way is to use ON LOCAL, I'm not sure though...
I have left this dump.
User avatar
{Nathan}
Veteran
Posts: 1169
Joined: Thu Aug 19, 2004 6:08 pm
Location: The wetlands of central Ohio, USA
Contact:

Post 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.
Image
Jan van de Poll

Module error

Post 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
Post Reply