Exceptions.
More...
Go to the source code of this file.
|
#define | ST_EXCEPTIONS_EN 0 |
| Exceptions enabled.
|
|
#define | ST_RAISE(lvl, e) |
| Raise an exception.
|
|
#define | ST_ENSURE(cond, lvl, e) |
| Raise an exception if the condition is not met.
|
|
#define | ST_ENSURE_MEM(ptr, lvl) |
| Raise an exception and return NULL if the pointer is NULL.
|
|
|
static const struct StException | st_except_null_param = {"Null param."} |
| Exception: "null_param".
|
|
static const struct StException | st_except_alloc_fail = {"Memory allocation failed."} |
| Exception: "alloc_fail".
|
|
static const struct StException | st_except_sem_fail = {"Semaphore failure."} |
| Exception: "sem_fail".
|
|
static const struct StException | st_except_mutex_fail = {"Mutex failure."} |
| Exception: "mutex_fail".
|
|
static const struct StException | st_except_not_supported = {"Not supported."} |
| Exception: "not_supported".
|
|
static const struct StException | st_except_sanity_fail = {"Sanity check failed."} |
| Exception: "sanity_fail".
|
|
◆ ST_ENSURE
#define ST_ENSURE |
( |
|
cond, |
|
|
|
lvl, |
|
|
|
e |
|
) |
| |
Value: do { \
if (!(cond)) { \
ST_RAISE(lvl, e); \
} \
} while (0)
Raise an exception if the condition is not met.
- Parameters
-
[in] | cond | The condition. |
[in] | lvl | The exception level: WARNING or ERROR. |
[in] | e | The exception. |
◆ ST_ENSURE_MEM
#define ST_ENSURE_MEM |
( |
|
ptr, |
|
|
|
lvl |
|
) |
| |
Value: do { \
if ((ptr) == NULL) { \
ST_RAISE(lvl, null_param); \
return NULL; \
} \
} while (0)
Raise an exception and return NULL if the pointer is NULL.
- Parameters
-
[in] | ptr | The pointer. |
[in] | lvl | Exception level. |
◆ ST_RAISE
#define ST_RAISE |
( |
|
lvl, |
|
|
|
e |
|
) |
| |
Value: do { \
\
ST_TRACE( \
ST_ERROR, NULL,
"%s:%d: %s", __FILE__, \
__LINE__, st_except_##e.reason); \
st_except( \
st_except_##e.reason, __FILE__, \
__LINE__); \
ST_TRACE( \
__LINE__, st_except_##e.reason); \
} else { \
ST_TRACE( \
ST_ERROR, NULL,
"%s:%d: %s", __FILE__, \
} \
} while (0)
static const struct StException st_except_not_supported
Exception: "not_supported".
Definition except.h:150
#define ST_EXCEPTIONS_EN
Exceptions enabled.
Definition except.h:51
StTraceLvl
Trace level.
Definition trace.h:75
@ ST_WARNING
warning trace level.
Definition trace.h:79
@ ST_ERROR
error trace level.
Definition trace.h:80
const char * reason
The reason that caused the exception.
Definition except.h:129
Raise an exception.
- Parameters
-
[in] | lvl | The exception level (WARNING or ERROR). |
[in] | e | The exception. |