CPU_SW_EXCEPTION
Description
Traps an unrecoverable software exception.
Files
cpu_core.h
Prototype
CPU_SW_EXCEPTION();
Arguments
err_rtn_val
Error type and/or value of the calling function to return.
Returned Value
None.
Required Configuration
None.
Notes / Warnings
- Deadlocks the current code execution—whether multi-tasked/-processed/-threaded or single-threaded—when the current code execution cannot gracefully recover or report a fault or exception condition.
Example Usage
void Fnct (CPU_ERR *p_err) { if (p_err == (CPU_ERR *)0) { /* If 'p_err' NULL, cannot return error ... */ CPU_SW_EXCEPTION(;); /* ... so trap invalid argument exception. */ } ... }
Developer-Implemented Examples
CPU_SW_EXCEPTION()
may be developer-implemented to output and/or handle any error or exception conditions; but since CPU_SW_EXCEPTION()
is intended to trap unrecoverable software conditions, it is recommended that developer-implemented versions prevent execution of any code following calls to CPU_SW_EXCEPTION()
by deadlocking the code.
#define CPU_SW_EXCEPTION(err_rtn_val) \ do { \ Log(__FILE__, __LINE__); \ CPU_SW_Exception(); \ /* SHOULD deadlock to prevent further code execution. */ } while (0)
However, if execution of code following calls to CPU_SW_EXCEPTION()
is required (e.g. for automated testing); it is recommended that the last statement in developer-implemented versions be to return from the current function to prevent possible software exceptions in the current function from triggering CPU and/or hardware exceptions. (Note that err_rtn_val
in the return statement must not be enclosed in parentheses. This allows CPU_SW_EXCEPTION()
to return from functions that return void
, i.e. no return type or value.)
#define CPU_SW_EXCEPTION(err_rtn_val) \ do { \ Log(__FILE__, __LINE__); \ return err_rtn_val; \ /* MUST NOT enclose 'err_rtn_val' in parentheses. */ } while (0)