Lumiera  0.pre.03
»edit your freedom«
error.h
Go to the documentation of this file.
1 /*
2  ERROR.h - Lumiera Error handling interface (C-style)
3 
4  Copyright (C)
5  2008, Christian Thaeter <ct@pipapo.org>
6 
7   **Lumiera** is free software; you can redistribute it and/or modify it
8   under the terms of the GNU General Public License as published by the
9   Free Software Foundation; either version 2 of the License, or (at your
10   option) any later version. See the file COPYING for further details.
11 
12 */
13 
14 
34 #ifndef LUMIERA_ERROR_H
35 #define LUMIERA_ERROR_H
36 
37 #ifdef __cplusplus
38 extern "C" {
39 #elif 0
40 } /* fixes broken emacs indenting */
41 #endif
42 
43 
44 #include <nobug.h>
45 #include <stdlib.h>
46 
47 
48 typedef const char* lumiera_err;
49 
54 #define LUMIERA_DIE(err) \
55  do { NOBUG_ERROR(NOBUG_ON, "Fatal Error: %s ", strchr(LUMIERA_ERROR_##err, ':')); abort(); } while(0)
56 
62 #define LUMIERA_ERROR_DECLARE(err) \
63 extern lumiera_err const LUMIERA_ERROR_##err
64 
71 #define LUMIERA_ERROR_DEFINE(err, msg) \
72 lumiera_err const LUMIERA_ERROR_##err = "LUMIERA_ERROR_" #err ":" msg
73 
82 #define LUMIERA_ERROR_SET(flag, err, extra) \
83  do { \
84  const char* theextra = extra; \
85  ERROR (flag, "%s%s%s", strchr(LUMIERA_ERROR_##err, ':')+1, theextra?": ":"", theextra?theextra:""); \
86  lumiera_error_set(LUMIERA_ERROR_##err, theextra); \
87  } while (0)
88 
97 #define LUMIERA_ERROR_SET_ALERT(flag, err, extra) \
98  do { \
99  const char* theextra = extra; \
100  ALERT (flag, "%s%s%s", strchr(LUMIERA_ERROR_##err, ':')+1, theextra?": ":"", theextra?theextra:""); \
101  lumiera_error_set(LUMIERA_ERROR_##err, theextra); \
102  } while (0)
103 
112 #define LUMIERA_ERROR_SET_CRITICAL(flag, err, extra) \
113  do { \
114  const char* theextra = extra; \
115  CRITICAL (flag, "%s%s%s", strchr(LUMIERA_ERROR_##err, ':')+1, theextra?": ":"", theextra?theextra:"");\
116  lumiera_error_set(LUMIERA_ERROR_##err, theextra); \
117  } while (0)
118 
127 #define LUMIERA_ERROR_SET_WARNING(flag, err, extra) \
128  do { \
129  const char* theextra = extra; \
130  WARN (flag, "%s%s%s", strchr(LUMIERA_ERROR_##err, ':')+1, theextra?": ":"", theextra?theextra:""); \
131  lumiera_error_set(LUMIERA_ERROR_##err, theextra); \
132  } while (0)
133 
142 lumiera_err
143 lumiera_error_set (lumiera_err nerr, const char* extra);
144 
149 const char*
150 lumiera_error_extra (void);
151 
158 lumiera_err
159 lumiera_error (void);
160 
161 
169 lumiera_err
170 lumiera_error_peek (void);
171 
172 
180 int
181 lumiera_error_expect (lumiera_err expected);
182 
183 
184 /*
185  predefined errors
186 */
187 LUMIERA_ERROR_DECLARE (ERRNO);
188 LUMIERA_ERROR_DECLARE (UNKNOWN);
189 
190 #ifdef __cplusplus
191 } /* extern "C" */
192 #endif
193 #endif /* LUMIERA_ERROR_H */
lumiera_err lumiera_error_set(lumiera_err nerr, const char *extra)
Set error state for the current thread.
Definition: error-state.c:96
const char * lumiera_error_extra(void)
Query the extra context for the last error.
Definition: error-state.c:126
#define LUMIERA_ERROR_DECLARE(err)
Forward declare an error constant.
Definition: error.h:62
int lumiera_error_expect(lumiera_err expected)
Expect some error Check that the current error state matches some expectation, if true then the error...
Definition: error-state.c:139
lumiera_err lumiera_error(void)
Get and clear current error state.
Definition: error-state.c:115
lumiera_err lumiera_error_peek(void)
Check current error state without clearing it Please avoid this function and use lumiera_error() if p...
Definition: error-state.c:133