ERIS Pipeline Reference Manual 1.8.15
eris_ifu_error.h
1 /*
2 * This file is part of the ERIS IFU Pipeline
3 * Copyright (C) 2002,2003 European Southern Observatory
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 */
19
40#ifndef ERIS_IFU_ERROR_H
41#define ERIS_IFU_ERROR_H
42
43/*-----------------------------------------------------------------------------
44 Includes
45 -----------------------------------------------------------------------------*/
46
47#include <cpl.h>
48
49/*-----------------------------------------------------------------------------
50 Defines
51 -----------------------------------------------------------------------------*/
52/* ToDo: look at the following */
53#if defined HAVE_DECL___FUNC__ && !HAVE_DECL___FUNC__
54#ifndef __func__
55#define __func__ ""
56#endif
57#endif
58/*----------------------------------------------------------------------------*/
63/*----------------------------------------------------------------------------*/
64
67/*-----------------------------------------------------------------------------
68 Functional Macros
69 -----------------------------------------------------------------------------*/
70
71/*----------------------------------------------------------------------------*/
155/*----------------------------------------------------------------------------*/
156#define TRY \
157 int eris_ifu_error_is_set_where = 0, \
158 eris_ifu_error_catch_call_flag; \
159 cpl_errorstate eris_ifu_error_state; \
160 \
161 eris_ifu_error_state = cpl_errorstate_get(); \
162 \
163 do
164
165/*----------------------------------------------------------------------------*/
172/*----------------------------------------------------------------------------*/
173#define CATCH \
174 while (0); \
175 \
176 goto _ERIS_IFU_CATCH_LABEL_; /* avoid warning if not used */ \
177 _ERIS_IFU_CATCH_LABEL_: \
178 \
179 if ((eris_ifu_error_catch_call_flag = \
180 !cpl_errorstate_is_equal(eris_ifu_error_state))) \
181 { \
182 if (!eris_ifu_error_is_set_where) \
183 cpl_error_set_where(__func__); \
184 } \
185 if (eris_ifu_error_catch_call_flag)
186
187/*----------------------------------------------------------------------------*/
197/*----------------------------------------------------------------------------*/
198#define GET_NEW_ERROR(void) \
199 (cpl_errorstate_is_equal(eris_ifu_error_state) ? \
200 CPL_ERROR_NONE : \
201 cpl_error_get_code() \
202 )
203
204/*----------------------------------------------------------------------------*/
212/*----------------------------------------------------------------------------*/
213#define RECOVER(void) \
214 cpl_errorstate_set(eris_ifu_error_state)
215
216/*----------------------------------------------------------------------------*/
224/*----------------------------------------------------------------------------*/
225#define SET_ERROR(code) \
226do { \
227 if (code != CPL_ERROR_NONE) \
228 { \
229 cpl_error_set(__func__, code); \
230 eris_ifu_error_is_set_where = __LINE__; \
231 } \
232 else \
233 RECOVER(); \
234} while (0)
235
236/*----------------------------------------------------------------------------*/
245/*----------------------------------------------------------------------------*/
246#define SET_ERROR_MSG(code, msg) \
247do { \
248 if (code != CPL_ERROR_NONE) \
249 { \
250 cpl_error_set_message(__func__, code, msg); \
251 eris_ifu_error_is_set_where = __LINE__; \
252 } \
253 else \
254 RECOVER(); \
255} while (0)
256
257/*----------------------------------------------------------------------------*/
265/*----------------------------------------------------------------------------*/
266#define CHECK_ERROR_STATE(void) \
267do { \
268 if (!cpl_errorstate_is_equal(eris_ifu_error_state)) \
269 { \
270 cpl_error_set_where(__func__); \
271 eris_ifu_error_is_set_where = __LINE__; \
272 ERIS_IFU_TRY_EXIT(); \
273 } \
274} while (0)
275
276/*----------------------------------------------------------------------------*/
285/*----------------------------------------------------------------------------*/
286#define CHECK_ERROR_STATE_MSG(msg) \
287do { \
288 if (!cpl_errorstate_is_equal(eris_ifu_error_state)) \
289 { \
290 cpl_error_set_where(__func__); \
291 cpl_msg_error(__func__, "%s", msg); \
292 eris_ifu_error_is_set_where = __LINE__; \
293 ERIS_IFU_TRY_EXIT(); \
294 } \
295} while (0)
296
297/*----------------------------------------------------------------------------*/
305/*----------------------------------------------------------------------------*/
306#define BRK_WITH_ERROR(code) \
307do { \
308 cpl_error_set(__func__, code); \
309 eris_ifu_error_is_set_where = __LINE__; \
310 ERIS_IFU_TRY_EXIT(); \
311} while (0)
312
313/*----------------------------------------------------------------------------*/
321/*----------------------------------------------------------------------------*/
322#define BRK_WITH_ERROR_MSG(code, ...) \
323do { \
324 cpl_error_set_message(__func__, code, __VA_ARGS__); \
325 eris_ifu_error_is_set_where = __LINE__; \
326 ERIS_IFU_TRY_EXIT(); \
327} while (0)
328
329/*----------------------------------------------------------------------------*/
338/*----------------------------------------------------------------------------*/
339#define BRK_IF_ERROR(function) \
340do { \
341 if ((function) != CPL_ERROR_NONE) \
342 { \
343 cpl_error_set_where(__func__); \
344 eris_ifu_error_is_set_where = __LINE__ ; \
345 ERIS_IFU_TRY_EXIT(); \
346 } \
347} while (0)
348
349/*----------------------------------------------------------------------------*/
359/*----------------------------------------------------------------------------*/
360#define BRK_IF_NULL(function) \
361do { \
362 if ((function) == NULL) \
363 { \
364 cpl_error_set_where(__func__); \
365 eris_ifu_error_is_set_where = __LINE__ ; \
366 ERIS_IFU_TRY_EXIT(); \
367 } \
368} while (0)
369
370/*----------------------------------------------------------------------------*/
379/*----------------------------------------------------------------------------*/
380#define ERIS_IFU_TRY_EXIT_IF_NOT(condition) \
381do { \
382 if (!(condition)) \
383 { \
384 cpl_error_set_where(__func__); \
385 eris_ifu_error_is_set_where = __LINE__; \
386 ERIS_IFU_TRY_EXIT(); \
387 } \
388} while (0)
389
390/*----------------------------------------------------------------------------*/
399/*----------------------------------------------------------------------------*/
400#define ERIS_IFU_TRY_EXIT(void) \
401 goto _ERIS_IFU_CATCH_LABEL_
402
409#define ASSURE(condition, error, ...) \
410do if (!(condition)) { \
411 cpl_error_set_message(cpl_func, \
412 error, \
413 __VA_ARGS__); \
414 eris_ifu_error_is_set_where = __LINE__; \
415 ERIS_IFU_TRY_EXIT(); \
416} while(0)
417
418/*----------------------------------------------------------------------------*/
426/*----------------------------------------------------------------------------*/
427#define CATCH_MSG() \
428do { \
429 cpl_msg_error(cpl_func, \
430 "%s (Code %d) in %s", \
431 cpl_error_get_message(), \
432 cpl_error_get_code(), \
433 cpl_error_get_where()); \
434} while (0)
435
436/*----------------------------------------------------------------------------*/
444/*----------------------------------------------------------------------------*/
445#define CATCH_MSGS() \
446do { \
447 cpl_errorstate_dump(0, CPL_FALSE, NULL); \
448} while (0)
449
452/*-----------------------------------------------------------------------------
453 Declaration Block
454 -----------------------------------------------------------------------------*/
455
458#ifdef __cplusplus
459extern "C" {
460#endif
461
462/*----------------------------------------------------------------------------*/
463
464#ifdef __cplusplus
465} /* extern "C" */
466#endif
467
468#endif /* ERIS_IFU_PRIV_ERROR_H */
469