Texas Instruments TI89 Developer Guide - Page 137
Error Handling, Throwing an Error, Delayed Error Messages
UPC - 033317198566
View all Texas Instruments TI89 manuals
Add to My Manuals
Save this manual to your list of manuals |
Page 137 highlights
95 10. 10.1. 10.2. Error Handling This chapter describes the Advanced Mathematics Software (AMS) implementation of error handling - how to throw errors, why you might want to throw an error, how to catch errors, and how to clean up when an error occurs. Throwing an Error Your application or ASM program can signal exceptional conditions by throwing an error. Calling ER_throwVar in your app diverts execution to an error handler, typically the system error handler. ER_throwVar accepts one argument, an integer in the range 0 to 0xEFF. System error numbers range from 0x000 to 0x7FF. Application-defined errors begin at OO_FIRST_APP_STRING (0x800). Look in tiams.h for macros beginning with ER_ for predefined error numbers. An error message is associated with each predefined error number. Perhaps the condition most frequently needing special attention is the case when HeapAlloc cannot fulfill a request for memory. HeapAlloc returns H_NULL if it cannot allocate the requested amount of memory. Your app should always test the return value of HeapAlloc. Under most circumstances, if your app cannot allocate the memory it needs, it should throw an error. h = HeapAlloc(BUF_SIZE); if (h == H_NULL) ER_throwVar(ER_MEMORY); /* error number defined in tiams.h */ The system error handler catches this error and displays a dialog box indicating there was a memory error. Note: Think of ER_throwVar as a long jump rather than a subroutine call. Execution does not return from the ER_throwVar call. Some AMS routines may throw an error instead of returning an error code. HeapAllocThrow, for example, tries to allocate memory but throws the ER_MEMORY error automatically if it fails. Macro ER_throw works like ER_throwVar but accepts only integer constants. The Sierra C™ compiler generates more compact code for the ER_throw macro. Delayed Error Messages You should not throw an error while processing events CM_START, CM_ACTIVATE, CM_FOCUS, CM_UNFOCUS, CM_DEACTIVATE, CM_QUIT, CM_WPAINT, CM_INSTALL, CM_UNINSTALL, CM_PACK, CM_UNPACK, TI-89 / TI-92 Plus Developer Guide Not for Distribution Beta Version January 26, 2001