exip  Alpha 0.5.4
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
bin/headers/errorHandle.h
Go to the documentation of this file.
1 /*==================================================================*\
2 | EXIP - Embeddable EXI Processor in C |
3 |--------------------------------------------------------------------|
4 | This work is licensed under BSD 3-Clause License |
5 | The full license terms and conditions are located in LICENSE.txt |
6 \===================================================================*/
7 
18 #ifndef ERRORHANDLE_H_
19 #define ERRORHANDLE_H_
20 
21 #include "exipConfig.h"
22 
23 #define INFO 1
24 #define WARNING 2
25 #define ERROR 3
26 
107 #if EXIP_DEBUG == ON
108 
109 # include <stdio.h>
110 
111 /* Platform specific debugging character output */
112 # ifndef DEBUG_CHAR_OUTPUT
113 # define DEBUG_CHAR_OUTPUT(character) do {putchar (character);} while(0)
114 # endif
115 
116 /* Platform specific debugging formatted output */
117 # ifndef DEBUG_OUTPUT
118 # define DEBUG_OUTPUT(msg) do {printf msg;} while(0)
119 # endif
120 
121 # ifndef EXIP_DEBUG_LEVEL
122 # define EXIP_DEBUG_LEVEL INFO
123 # endif
124 
125 # define DEBUG_MSG(level, module, msg) do { if (level >= EXIP_DEBUG_LEVEL && module == ON) { DEBUG_OUTPUT(msg); } } while(0)
126 #else
127 # define DEBUG_MSG(level, module, msg)
128 #endif /* EXIP_DEBUG */
129 
130 // IMPORTANT: remember to keep in sync with "errorCodeStrings[]" in procTypes.c!
131 /* Definitions for error constants. */
133 {
135  EXIP_OK = 0,
191 };
192 
193 typedef enum errorCode errorCode;
194 
195 #if EXIP_DEBUG == ON
196  extern const char* errorCodeStrings[];
197 # define GET_ERR_STRING(indx) errorCodeStrings[indx]
198 #else
199 # define GET_ERR_STRING(indx) ""
200 #endif
201 
202 # define TRY(func) do { tmp_err_code = func;\
203  if (tmp_err_code != EXIP_OK) { \
204  DEBUG_MSG(ERROR, EXIP_DEBUG, ("\n>Error %s:%d at %s, line %d", GET_ERR_STRING(tmp_err_code), tmp_err_code, __FILE__, __LINE__)); \
205  return tmp_err_code; } } while(0)
206 
207 # define TRY_CATCH(func, cblock) do { tmp_err_code = func;\
208  if (tmp_err_code != EXIP_OK) { \
209  DEBUG_MSG(ERROR, EXIP_DEBUG, ("\n>Error %s:%d at %s, line %d", GET_ERR_STRING(tmp_err_code), tmp_err_code, __FILE__, __LINE__)); \
210  cblock;\
211  return tmp_err_code; } } while(0)
212 
213 #endif /* ERRORHANDLE_H_ */