51Degrees Common C/C++  4.1

A shared functionality library that is used by 51Degrees products

exceptions.h

1 /* *********************************************************************
2  * This Source Code Form is copyright of 51 Degrees Mobile Experts Limited.
3  * Copyright 2019 51 Degrees Mobile Experts Limited, 5 Charlotte Close,
4  * Caversham, Reading, Berkshire, United Kingdom RG4 7BY
5  *
6  * This Source Code Form is subject to the terms of the Mozilla Public
7  * License, v. 2.0.
8  *
9  * If a copy of the MPL was not distributed with this file, You can obtain
10  * one at http://mozilla.org/MPL/2.0/.
11  *
12  * This Source Code Form is "Incompatible With Secondary Licenses", as
13  * defined by the Mozilla Public License, v. 2.0.
14  * ******************************************************************** */
15 
16 #ifndef FIFTYONE_DEGREES_EXCEPTIONS_H_INCLUDED
17 #define FIFTYONE_DEGREES_EXCEPTIONS_H_INCLUDED
18 
92 #include "status.h"
93 
94 #ifdef __cplusplus
95 #define EXTERNAL extern "C"
96 #else
97 #define EXTERNAL
98 #endif
99 
100 #ifndef FIFTYONE_DEGREES_EXCEPTIONS_DISABLED
101 
109 EXTERNAL typedef struct fiftyone_degrees_exception_t {
110  const char *file;
111  const char *func;
112  int line;
115 
120 #define FIFTYONE_DEGREES_EXCEPTION_SET(s) \
121 if (exception != NULL) { \
122 exception->file = __FILE__; \
123 exception->func = __func__; \
124 exception->line = __LINE__; \
125 exception->status = s; \
126 }
127 
131 #define FIFTYONE_DEGREES_EXCEPTION_CLEAR \
132 exception->file = NULL; \
133 exception->func = NULL; \
134 exception->line = -1; \
135 exception->status = FIFTYONE_DEGREES_STATUS_NOT_SET;
136 
140 #define FIFTYONE_DEGREES_EXCEPTION_OKAY \
141 (exception == NULL || exception->status == FIFTYONE_DEGREES_STATUS_NOT_SET)
142 
143 #ifdef FIFTYONE_DEGREES_EXCEPTIONS_HPP
144 
149 #define FIFTYONE_DEGREES_EXCEPTION_THROW \
150 if (FIFTYONE_DEGREES_EXCEPTION_OKAY == false) { \
151 throw FiftyoneDegrees::Common::FatalException(exception); \
152 }
153 
154 #else
155 
159 #define FIFTYONE_DEGREES_EXCEPTION_THROW \
160 fiftyoneDegreesExceptionCheckAndExit(exception);
161 
162 #endif
163 
164 #else
165 
166 EXTERNAL typedef void* fiftyoneDegreesException;
167 
168 #define FIFTYONE_DEGREES_EXCEPTION_CLEAR exception = NULL;
169 
170 #define FIFTYONE_DEGREES_EXCEPTION_SET(s) exception = NULL;
171 
172 #define FIFTYONE_DEGREES_EXCEPTION_OKAY (exception == exception)
173 
174 #define FIFTYONE_DEGREES_EXCEPTION_THROW
175 
176 #endif
177 
181 #define FIFTYONE_DEGREES_EXCEPTION_CREATE \
182 fiftyoneDegreesException exceptionValue; \
183 fiftyoneDegreesException *exception = &exceptionValue; \
184 FIFTYONE_DEGREES_EXCEPTION_CLEAR
185 
189 #define FIFTYONE_DEGREES_EXCEPTION_FAILED \
190 (FIFTYONE_DEGREES_EXCEPTION_OKAY == false)
191 
198 EXTERNAL const char* fiftyoneDegreesExceptionGetMessage(
199  fiftyoneDegreesException *exception);
200 
207  fiftyoneDegreesException *exception);
208 
213 #endif
const char * func
Function generating the exception.
Definition: exceptions.h:111
fiftyoneDegreesStatusCode status
Status code to assign.
Definition: exceptions.h:113
fiftyoneDegreesStatusCode
Status returned from the initialisation of a resource.
Definition: status.h:75
EXTERNAL void fiftyoneDegreesExceptionCheckAndExit(fiftyoneDegreesException *exception)
If the exception is set then will print a message to stderr and exit the process.
Definition: exceptionsc.c:53
int line
Line number generating the exception.
Definition: exceptions.h:112
const char * file
File generating the exception.
Definition: exceptions.h:110
EXTERNAL const char * fiftyoneDegreesExceptionGetMessage(fiftyoneDegreesException *exception)
Returns an English error message for the exception.
Definition: exceptionsc.c:21
Structure used to represent a 51Degrees exception and passed into methods that might generate excepti...
Definition: exceptions.h:109