ti/error.h

#include <ti/error.h>

Exceptions in languages like Python provide a structured way of handling rare error conditions. TI calls their implementation of this idea error handlers.

When the OS encounters an unsusal condition such as divide-by-zero or out-of-memory, it looks for an active error handler. If no active error handlers exist, the OS will display the ERR: screen. If an active error handler does exist, it gets control instead of showing the ERR: screen.

Unlike exception handlers, TI’s error handlers do not differentiate between error codes; the same error handler is called for all errors. However, error handlers do support nesting. If an handler decides that it can’t handle an error, it can rethrow it.

Warning

When a TI error handler is invoked, C++ destructors are not run even if the handler is outside the current scope! Therefore, you must be very careful with object creation while an error handler is active.

Similarly, although the toolchain supports C++, it does not support C++ exceptions, and TI error handlers are not a substitute for C++ exceptions.

API Documentation

TI CE OS errors; this is all the ERR:A MESSAGE screen stuff. You can use this to show custom error screens, as well as intercept errors to prevent the error screen from showing.

Authors

Matt “MateoConLechuga” Waltz

Jacob “jacobly” Young

Defines

os_AppErr1

String for custom error.

Can be used by calling os_ThrowError(OS_E_APPERR1);.

Note

String must be null-terminated, maximum of 12 characters.

os_AppErr2

String for custom error.

Can be used by calling os_ThrowError(OS_E_APPERR2);.

Note

String must be null-terminated, maximum of 12 characters.

OS_E_EDIT
OS_E_MASK
OS_E_OVERFLOW
OS_E_DIVBY0
OS_E_SINGULARMAT
OS_E_DOMAIN
OS_E_INCREMENT
OS_E_BREAK
OS_E_NONREAL
OS_E_SYNTAX
OS_E_DATATYPE
OS_E_ARGUMENT
OS_E_DIMMISMATCH
OS_E_DIMENSION
OS_E_UNDEFINED
OS_E_MEMORY
OS_E_INVALID
OS_E_ILLEGALNEST
OS_E_BOUND
OS_E_GRAPHRANGE
OS_E_ZOOM
OS_E_LABEL
OS_E_STAT
OS_E_SOLVER
OS_E_SINGULARITY
OS_E_SIGNCHANGE
OS_E_ITERATIONS
OS_E_BADGUESS
OS_E_STATPLOT
OS_E_TOLTOOSMALL
OS_E_RESERVED
OS_E_MODE
OS_E_LNKERR
OS_E_LNKMEMERR
OS_E_LNKTRANSERR
OS_E_LNKDUPERR
OS_E_LNKMEMFULL
OS_E_UNKNOWN
OS_E_SCALE
OS_E_IDNOTFOUND
OS_E_NOMODE
OS_E_VALIDATION
OS_E_LENGTH
OS_E_APPLICATION
OS_E_APPERR1
OS_E_APPERR2
OS_E_EXPIREDAPP
OS_E_BADADD
OS_E_ARCHIVED
OS_E_VERSION
OS_E_ARCHFULL
OS_E_VARIABLE
OS_E_DUPLICATE

Functions

void os_ThrowError(uint8_t error) __attribute__((noreturn))

Throws an OS error.

Parameters

error[in] Error code to throw

int os_PushErrorHandler(void) __attribute__((returns_twice))

This function can return twice (like setjmp).

First return always happens with a return value of 0. Second return only happens if an error occurs before os_PopErrorHandler is called, with the errNo as the return value.

int errno = os_PushErrorHandler();
if (errno) {
    // handle error, but no longer under the protection of the error handler so do not call os_PopErrorHandler()
} else {
    // run some code that may error
    os_PopErrorHandler();
}

Warning

This does not respect C++ destructors! So don’t use anything that requires a non-trivial destructor.

void os_PopErrorHandler(void)

Restores stack state after a call to os_PushErrorHandler.

Must be called with stack in the same state as it was when os_PushErrorHandler returned with 0, and should not be called along the error path.