Sturk 1.0.2
Publish-subscribe C implementation.
Loading...
Searching...
No Matches
except.h File Reference

Exceptions. More...

#include "st/logger/trace.h"
#include "st/os/sys.h"
Include dependency graph for except.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  StException
 Exception. More...
 

Macros

#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.
 

Variables

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".
 

Detailed Description

Exceptions.

Macro Definition Documentation

◆ ST_ENSURE

#define ST_ENSURE (   cond,
  lvl,
 
)
Value:
do { \
if (!(cond)) { \
ST_RAISE(lvl, e); \
} \
} while (0)

Raise an exception if the condition is not met.

Parameters
[in]condThe condition.
[in]lvlThe exception level: WARNING or ERROR.
[in]eThe 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]ptrThe pointer.
[in]lvlException level.

◆ ST_RAISE

#define ST_RAISE (   lvl,
 
)
Value:
do { \
enum StTraceLvl _lvl = (lvl); \
\
if (ST_ERROR == _lvl) { \
ST_TRACE( \
ST_ERROR, NULL, "%s:%d: %s", __FILE__, \
__LINE__, st_except_##e.reason); \
st_except( \
st_except_##e.reason, __FILE__, \
__LINE__); \
} else if (ST_WARNING == _lvl) { \
ST_TRACE( \
ST_WARNING, NULL, "%s:%d: %s", __FILE__, \
__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]lvlThe exception level (WARNING or ERROR).
[in]eThe exception.