Sturk 1.0.2
Publish-subscribe C implementation.
Loading...
Searching...
No Matches
except.h
Go to the documentation of this file.
1/*
2BSD 3-Clause License
3
4Copyright (c) 2025, Szymon Turno
5
6Redistribution and use in source and binary forms, with or without
7modification, are permitted provided that the following conditions are met:
8
91. Redistributions of source code must retain the above copyright notice, this
10 list of conditions and the following disclaimer.
11
122. Redistributions in binary form must reproduce the above copyright notice,
13 this list of conditions and the following disclaimer in the documentation
14 and/or other materials provided with the distribution.
15
163. Neither the name of the copyright holder nor the names of its
17 contributors may be used to endorse or promote products derived from
18 this software without specific prior written permission.
19
20THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
24FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
26SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
27CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
28OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30*/
31
38#ifndef ST_LOGGER_EXCEPT_H
39#define ST_LOGGER_EXCEPT_H
40
41#include "st/logger/trace.h"
42#include "st/os/sys.h"
43
44#ifndef ST_EXCEPTIONS_EN
45
51#define ST_EXCEPTIONS_EN 0
52
53#endif /* ST_EXCEPTIONS_EN */
54
63#define ST_RAISE(lvl, e) \
64 do { \
65 enum StTraceLvl _lvl = (lvl); \
66 \
67 if (ST_ERROR == _lvl) { \
68 ST_TRACE( \
69 ST_ERROR, NULL, "%s:%d: %s", __FILE__, \
70 __LINE__, st_except_##e.reason); \
71 if (ST_EXCEPTIONS_EN) \
72 st_except( \
73 st_except_##e.reason, __FILE__, \
74 __LINE__); \
75 } else if (ST_WARNING == _lvl) { \
76 ST_TRACE( \
77 ST_WARNING, NULL, "%s:%d: %s", __FILE__, \
78 __LINE__, st_except_##e.reason); \
79 } else { \
80 ST_TRACE( \
81 ST_ERROR, NULL, "%s:%d: %s", __FILE__, \
82 __LINE__, st_except_not_supported.reason); \
83 } \
84 } while (0)
85
95#define ST_ENSURE(cond, lvl, e) \
96 do { \
97 if (!(cond)) { \
98 ST_RAISE(lvl, e); \
99 } \
100 } while (0)
101
110#define ST_ENSURE_MEM(ptr, lvl) \
111 do { \
112 if ((ptr) == NULL) { \
113 ST_RAISE(lvl, null_param); \
114 return NULL; \
115 } \
116 } while (0)
117
129 const char* reason;
130};
131
134 = {"Null param."};
135
138 = {"Memory allocation failed."};
139
141static const struct StException st_except_sem_fail
142 = {"Semaphore failure."};
143
146 = {"Mutex failure."};
147
150 = {"Not supported."};
151
154 = {"Sanity check failed."};
155
156#endif /* ST_LOGGER_EXCEPT_H */
static const struct StException st_except_sem_fail
Exception: "sem_fail".
Definition except.h:142
static const struct StException st_except_sanity_fail
Exception: "sanity_fail".
Definition except.h:154
static const struct StException st_except_not_supported
Exception: "not_supported".
Definition except.h:150
static const struct StException st_except_alloc_fail
Exception: "alloc_fail".
Definition except.h:138
static const struct StException st_except_null_param
Exception: "null_param".
Definition except.h:134
static const struct StException st_except_mutex_fail
Exception: "mutex_fail".
Definition except.h:146
Trace.
Exception.
Definition except.h:123
const char * reason
The reason that caused the exception.
Definition except.h:129
System procedures.