![]() |
FINALLY | Language Extension |
error.h |
Begins the termination handler in a TRY...FINALLY...ENDFINAL block.
The macro FINALLY ends the protected block and begins the handler for code
which always has to be executed (see TRY for more info).
The variable errCode is
automatically created in the error handler, and it contains the error number to allow
the program to check what caused the error, or 0 if there was no error.
This variable is destroyed after the ENDFINAL statement.
Note: The macro FINALLY uses the ER_success function to end the protected
block, and ENDFINAL uses PASS to throw the
error signaled by errCode a second time.
Here is an example (called "Memory Error"), which demonstrates the use of this
macro:
// Allocate memory as long as possible, then throw an error // All allocated memory will be freed again! #define USE_TI89 // Compile for TI-89 #define USE_TI92PLUS // Compile for TI-92 Plus #define USE_V200 // Compile for V200 #define MIN_AMS 100 // Compile for AMS 1.00 or higher #define ENABLE_ERROR_RETURN // Enable Returning Errors to TIOS #include <tigcclib.h> // Include All Header Files #define BLOCK_SIZE 1024 void AllocRecursively(void) { void *ptr = malloc_throw (BLOCK_SIZE); TRY // Could do something with ptr here... AllocRecursively (); // Could still do something with ptr... FINALLY free (ptr); ENDFINAL } // Main Function void _main(void) { AllocRecursively (); }