Sturk 1.1.0
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 } while (0)
100
109#define ST_ENSURE_MEM(ptr, lvl) \
110 do { \
111 if ((ptr) == NULL) { \
112 ST_RAISE(lvl, null_param); \
113 return NULL; \
114 } \
115 } while (0)
116
117#endif /* ST_LOGGER_EXCEPT_H */
Trace.
System procedures.