Debugging programs and handling errors, Run-time errors, Debugging techniques – Texas Instruments PLUS TI-89 User Manual

Page 327: Error-handling commands

Advertising
background image

310 Chapter 17: Programming

17PROGRM.DOC TI-89/TI-92 Plus: Programming (English) Susan Gullord Revised: 02/23/01 1:14 PM Printed: 02/23/01 2:18 PM Page 310 of 40

The first step in debugging your program is to run it. The

TI

-89 / TI-92 Plus

automatically checks each executed command for

syntax errors. If there is an error, a message indicates the nature of
the error.

¦

To display the program in the
Program Editor, press ¸.
The cursor appears in the
approximate area of the error.

¦

To cancel program execution and return to the Home screen,
press N.

If your program allows the user to select from several options, be
sure to run the program and test each option.

Run-time error messages can locate syntax errors but not errors in
program logic. The following techniques may be useful.

¦

During testing, do not use local variables so that you can check
the variable values after the program stops. When the program is
debugged, declare the applicable variables as local.

¦

Within a program, temporarily insert

Disp

and

Pause

commands

to display the values of critical variables.

Disp

and

Pause

cannot be used in a user-defined function. To

temporarily change the function into a program, change

Func

and

EndFunc

to

Prgm

and

EndPrgm

. Use

Disp

and

Pause

to

debug the program. Then remove

Disp

and

Pause

and change

the program back into a function.

¦

To confirm that a loop is executed the correct number of times,
display the counter variable or the values in the conditional test.

¦

To confirm that a subroutine is executed, display messages such
as

"Entering subroutine"

and

"Exiting subroutine"

at the beginning and

end of the subroutine.

Command

Description

Try...EndTry

Defines a program block that lets the program
execute a command and, if necessary, recover from
an error generated by that command.

ClrErr

Clears the error status and sets the error number in
system variable

Errornum

to zero.

PassErr

Passes an error to the next level of the

Try...EndTry

block.

Debugging Programs and Handling Errors

After you write a program, you can use several techniques to
find and correct errors. You can also build an error-handling
command into the program itself.

Run-Time Errors

Debugging
Techniques

Error-Handling
Commands

Advertising
This manual is related to the following products: