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) Lumiera.org
5  2008, Christian Thaeter <ct@pipapo.org>
6 
7  This program is free software; you can redistribute it and/or
8  modify it under the terms of the GNU General Public License as
9  published by the Free Software Foundation; either version 2 of
10  the License, or (at your option) any later version.
11 
12  This program is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  GNU General Public License for more details.
16 
17  You should have received a copy of the GNU General Public License
18  along with this program; if not, write to the Free Software
19  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 
21 */
22 
23 
43 #ifndef LUMIERA_ERROR_H
44 #define LUMIERA_ERROR_H
45 
46 #ifdef __cplusplus
47 extern "C" {
48 #elif 0
49 } /* fixes broken emacs indenting */
50 #endif
51 
52 
53 #include <nobug.h>
54 #include <stdlib.h>
55 
56 
57 typedef const char* lumiera_err;
58 
63 #define LUMIERA_DIE(err) \
64  do { NOBUG_ERROR(NOBUG_ON, "Fatal Error: %s ", strchr(LUMIERA_ERROR_##err, ':')); abort(); } while(0)
65 
71 #define LUMIERA_ERROR_DECLARE(err) \
72 extern lumiera_err const LUMIERA_ERROR_##err
73 
80 #define LUMIERA_ERROR_DEFINE(err, msg) \
81 lumiera_err const LUMIERA_ERROR_##err = "LUMIERA_ERROR_" #err ":" msg
82 
91 #define LUMIERA_ERROR_SET(flag, err, extra) \
92  do { \
93  const char* theextra = extra; \
94  ERROR (flag, "%s%s%s", strchr(LUMIERA_ERROR_##err, ':')+1, theextra?": ":"", theextra?theextra:""); \
95  lumiera_error_set(LUMIERA_ERROR_##err, theextra); \
96  } while (0)
97 
106 #define LUMIERA_ERROR_SET_ALERT(flag, err, extra) \
107  do { \
108  const char* theextra = extra; \
109  ALERT (flag, "%s%s%s", strchr(LUMIERA_ERROR_##err, ':')+1, theextra?": ":"", theextra?theextra:""); \
110  lumiera_error_set(LUMIERA_ERROR_##err, theextra); \
111  } while (0)
112 
121 #define LUMIERA_ERROR_SET_CRITICAL(flag, err, extra) \
122  do { \
123  const char* theextra = extra; \
124  CRITICAL (flag, "%s%s%s", strchr(LUMIERA_ERROR_##err, ':')+1, theextra?": ":"", theextra?theextra:"");\
125  lumiera_error_set(LUMIERA_ERROR_##err, theextra); \
126  } while (0)
127 
136 #define LUMIERA_ERROR_SET_WARNING(flag, err, extra) \
137  do { \
138  const char* theextra = extra; \
139  WARN (flag, "%s%s%s", strchr(LUMIERA_ERROR_##err, ':')+1, theextra?": ":"", theextra?theextra:""); \
140  lumiera_error_set(LUMIERA_ERROR_##err, theextra); \
141  } while (0)
142 
151 lumiera_err
152 lumiera_error_set (lumiera_err nerr, const char* extra);
153 
158 const char*
159 lumiera_error_extra (void);
160 
167 lumiera_err
168 lumiera_error (void);
169 
170 
178 lumiera_err
179 lumiera_error_peek (void);
180 
181 
189 int
190 lumiera_error_expect (lumiera_err expected);
191 
192 
193 /*
194  predefined errors
195 */
196 LUMIERA_ERROR_DECLARE (ERRNO);
197 LUMIERA_ERROR_DECLARE (UNKNOWN);
198 
199 #ifdef __cplusplus
200 } /* extern "C" */
201 #endif
202 #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:105
const char * lumiera_error_extra(void)
Query the extra context for the last error.
Definition: error-state.c:135
#define LUMIERA_ERROR_DECLARE(err)
Forward declare an error constant.
Definition: error.h:71
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:148
lumiera_err lumiera_error(void)
Get and clear current error state.
Definition: error-state.c:124
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:142