Before You Post, Please Note...

-> Please Note: By Posting, you agree to submit the contents of your post to the Public Domain <- SEE: howto post to this blog

Friday, February 2, 2007

puppybasic intro ch. 14 - errors

green text is being edited and should not be considered  
relevant to the tutorial.
for a while, it will make up
the bulk of this section.

black text has been edited to be more accurate with
regards to puppybasic.

........................................................................
errors
1 of 10




an intro to puppybasic

chapter 14: errors







........................................................................

........................................................................
errors
2 of 10

you could do well to always trap and handle errors, i almost never
bother. if you write your program well, you might manage to avoid it.
this applies less to large programs. of course, sometimes error trapping
is quite useful.

whether you use error handling or not, your program, upon encountering
an error, can tell the user the name of the error. if you do not trap
your errors, the program will end as well. if you do use error handling,
you have the option of telling the user a more friendly interpretation
of the problem:
"I'm sorry, no file by that name exists in this folder."


........................................................................

........................................................................
errors
3 of 10

or even fixing it so the program can continue:

"That file does not exist. Create? (Y/N)"

you can even trap errors to detect which screen modes don't work. as
mentioned in the graphics section, there are several screen modes in
puppybasic, and they start with SCREEN 0, or text-only mode and range
from 0 to 13. so, you can tell your program to go to all the possible
screen modes: (none of this is true, this tutorial is being edited.)




........................................................................

........................................................................
errors
4 of 10

okscreen$ = SPACE$(14)
ON ERROR GOTO oops
FOR q = 0 TO 13
SCREEN q
NEXT q: nomorec = 1

and then when it tries to SCREEN [not an available mode] it will cause
an error 5, and GOTO the "oops" routine:





........................................................................

........................................................................
errors
5 of 10

oops:
IF nomorec = 0 THEN
IF ERR = 5 THEN MID$(okscreen$, q + 1) = "x"
END IF
RESUME NEXT

which adds an "x" under the part of the variable okscreen$ for that
mode.





........................................................................

........................................................................
errors
6 of 10

the command RESUME NEXT tells the program "don't worry about that last
error..." and the program then runs the next line, which is the "NEXT q"
of the FOR... NEXT loop.

when you're done trying all the modes, you can go back to SCREEN 0,
which is the default, and should always work:

SCREEN 0: WIDTH 80 'WIDTH 80 should always work, otherwise, remove it.

then print a guide for the numbers 0 to 13:



........................................................................

........................................................................
errors
7 of 10

PRINT " 1111"
PRINT "01234567890123"

and under that:

PRINT: PRINT okscreen$
END 'don't forget to put an END statement between
'your program and routines.

now your program will put a little "x" under the modes that don't work
on your computer!


........................................................................

........................................................................
errors
8 of 10

if we went over this section too fast: here is a review:

ON ERROR... GOTO linelabel

tells the program what routine to goto when an error occurs. there is no
"ON ERROR... GOSUB."

IF ERR=n THEN

will do something in response to the specific error... (you can also use
"SELECT CASE ERR" for handling this part.)


........................................................................

........................................................................
errors
9 of 10

RESUME NEXT

goes back to the part of the program where the error occured, but it
goes to the first line AFTER the problem.

note: error code 5 is "illegal function call" - the error you get when
you try to change to an unavailable mode, although there are other
possible causes.





........................................................................

........................................................................
errors
10 of 10

there are at least a couple other commands for error handling, but
unless you want them enough to look them up, you probably won't ever
need them.


-= end of chapter 14 =-







........................................................................
an intro to puppybasic (chapter 14)
this content is public domain.
........................................................................


click here to go back to the contents page

0 comments: