The Try Command

We're glad you came by, but you might find what you're looking for elsewhere.

TI-Basic Developer is not the site it once was. While its information on commands and other calculator features remains almost second-to-none, its forum, archives, and even hosting service, Wikidot, have been decaying for years. The calculator community would love to see what you're working on, or help you in your next coding adventure, but TI-Basic Developer is no longer the place to do it.

Instead, you should head over to Cemetech (primarily American) or TI-Planet (primarily international). Both are active, well-established forums with their own archives, chatrooms, reference material, and abundant coding tools and resources. We'll see you there, we hope.

try.png

Command Summary

Catches errors that occur in a block of code.

Command Syntax

:Try
(block of code)
:Else
(error-catching code)
:EndTry

Menu Location

Starting in the program editor:

  • Press F2 to enter the Control menu.
  • Press 2 to enter the If..Then submenu.
  • Press 4 to select Try..EndTry.

Calculator Compatibility

This command works on all calculators.

Token Size

2 bytes for Try;
2 bytes for Else;
2 bytes for EndTry.

The Try command is used to "catch" errors that occur in a block of code. If an error occurs in a Try..EndTry code block, it doesn't display an error message and exit the program. Instead, it records the type of error in the system variable errornum, and jumps to the Else section of the Try..EndTry block.

Here, you have several options. By checking the Errors page, you can test errornum for specific values to find out what kind of error happened. Ultimately, you'll want to use one of two commands:

  • ClrErr to cancel the error.
  • PassErr to display the error message and exit the program, as usual.

Here is an example of Try..EndTry in action:

:Try
: UnArchiv var
:Else
: Disp "var is undefined!"
: ClrErr
:EndTry

For most errors, Try..EndTry blocks aren't the way to go because you want to prevent them in the first place. They are a good way to handle special cases or circumstances out of your control. Here are two situations you might use Try..EndTry in:

  • If your program uses external variables, you might surround that part of the code in a Try..EndTry block, rather than do all the tests to make sure they are unlocked, unarchived, etc.
  • If your program requires specially-formatted input, instead of sanity checking it first you might let the program take untreated input, and catch the errors that result from an incorrect format.

Error Conditions

290 - EndTry is missing the matching Else statement happens when the Try..EndTry block doesn't contain an Else.

490 - Invalid in Try..EndTry block happens when ??.

Related Commands

See Also

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-Noncommercial 2.5 License.
Click here to edit contents of this page.
Click here to toggle editing of individual sections of the page (if possible). Watch headings for an "edit" link when available.
Append content without editing the whole page source.
Check out how this page has evolved in the past.
If you want to discuss contents of this page - this is the easiest way to do it.
View and manage file attachments for this page.
A few useful tools to manage this Site.
Change the name (also URL address, possibly the category) of the page.
View wiki source for this page without editing.
View/set parent page (used for creating breadcrumbs and structured layout).
Notify administrators if there is objectionable content in this page.
Something does not work as expected? Find out what you can do.
General Wikidot.com documentation and help section.
Wikidot.com Terms of Service - what you can, what you should not etc.
Wikidot.com Privacy Policy.

AltStyle によって変換されたページ (->オリジナル) /