on 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
sid6.7
Veteran
Posts: 318
Joined: Tue Jun 21, 2005 8:51 am
Location: west USA
Contact:

on error

Post by sid6.7 »

for the best effect where should the on error goto statement be?
after every input statement? or at the very end of the program...
MystikShadows
Veteran
Posts: 703
Joined: Sun Nov 14, 2004 7:36 am
Contact:

Post by MystikShadows »

QB and FB imply a local error management. This means that your ON ERROR should be at the start of every subroutine :-).
When God created light, so too was born, the first Shadow!

MystikShadows

Need hosting? http://www.jc-hosting.net

Interested in Text & ASCII development? Look no further!
http://www.ascii-world.com
sid6.7
Veteran
Posts: 318
Joined: Tue Jun 21, 2005 8:51 am
Location: west USA
Contact:

Post by sid6.7 »

so if i dont use subroutines and only use gotos will that work at all?

IE

goto blablah



$$$:
on error goto bleep?
code code
code code
.
.
.
.
end




bleep
print err code
end

thanks mystik...
everytime i use your help i've been adding you to my credits
for each program as a thank you if you dont mind..
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} »

Please use code tags. But to something like this:

Code: Select all

ON ERROR GOTO Error
...
...
...
(an error is here, it goes to error)

Error:

PRINT "There has been an error. We are all screwed."
Image
Antoni
Veteran
Posts: 132
Joined: Wed Jun 15, 2005 3:01 pm
Contact:

Post by Antoni »

I'm afraid Mystik Shadows is wrong in this case...
QB4.5 has no LOCAL error handling, whatever the online help says (perhaps a bug) ... Local error handling works only with PDS 7.1..or FB.

The error handling routines must be at the end of the main program, or in the main part of the modules. They can't be in the SUBS/FUNCTIONS in QB 4.5

ON ERROR can be used anywhere the program an error could break it and will be active until an ON ERROR GOTO 0 is found. Some people puts it at the first line of the program and leaves it active until it ends. I don't remember if activating ON ERROR produces any overhead....

In PDS 7.1 and FB you can use ON LOCAL ERROR, allowing you to have error handlers local to SUBS and FUNCTIONS.
User avatar
matt2jones
Veteran
Posts: 80
Joined: Sat Feb 19, 2005 8:29 am
Location: elsewhere
Contact:

Post by matt2jones »

Yeah, for a catch all errorhandler, just put it after you've dimmed all your vars, but before you're program has begun doing things, and have the errorhandler as a label down on the bottom of the main module... or whatever you call the page that you start on. DON'T PUT IT IN A SUB OR FUNCTION, it won't be able to find it.

Well, I managed to repeat everything that was said before me, while adding nothing new to the debate.

What I ment to say was I am one of the Some people [that] puts it at the first line of the program and leaves it active until it[the program] ends

matt blasts his face off with a shotgun.
Do not mistake Apathy for feeling Content.

http://www.disjointed.cjb.net - Short Storys
http://matt2jones.deviantart.com - Random Art
http://www.freewebs.com/matt2jones - WebComic
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} »

Finally.. matt is dead... thank god...
Image
Post Reply