51Degrees Device Detection C/C++  4.1

A device detection library that is used natively or by 51Degrees products

exceptions.h

1 /* *********************************************************************
2  * This Original Work 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 Original Work is licensed under the European Union Public Licence (EUPL)
7  * v.1.2 and is subject to its terms as set out below.
8  *
9  * If a copy of the EUPL was not distributed with this file, You can obtain
10  * one at https://opensource.org/licenses/EUPL-1.2.
11  *
12  * The 'Compatible Licences' set out in the Appendix to the EUPL (as may be
13  * amended by the European Commission) shall be deemed incompatible for
14  * the purposes of the Work and the provisions of the compatibility
15  * clause in Article 5 of the EUPL shall not apply.
16  *
17  * If using the Work as, or as part of, a network application, by
18  * including the attribution notice(s) required under Article 5 of the EUPL
19  * in the end user terms of the application under an appropriate heading,
20  * such notice(s) shall fulfill the requirements of that article.
21  * ********************************************************************* */
22 
23 #ifndef FIFTYONE_DEGREES_EXCEPTIONS_H_INCLUDED
24 #define FIFTYONE_DEGREES_EXCEPTIONS_H_INCLUDED
25 
99 #include "status.h"
100 
101 #ifdef __cplusplus
102 #define EXTERNAL extern "C"
103 #else
104 #define EXTERNAL
105 #endif
106 
107 #ifndef FIFTYONE_DEGREES_EXCEPTIONS_DISABLED
108 
116 EXTERNAL typedef struct fiftyone_degrees_exception_t {
117  const char *file;
118  const char *func;
119  int line;
122 
127 #define FIFTYONE_DEGREES_EXCEPTION_SET(s) \
128 if (exception != NULL) { \
129 exception->file = __FILE__; \
130 exception->func = __func__; \
131 exception->line = __LINE__; \
132 exception->status = s; \
133 }
134 
138 #define FIFTYONE_DEGREES_EXCEPTION_CLEAR \
139 exception->file = NULL; \
140 exception->func = NULL; \
141 exception->line = -1; \
142 exception->status = FIFTYONE_DEGREES_STATUS_NOT_SET;
143 
147 #define FIFTYONE_DEGREES_EXCEPTION_OKAY \
148 (exception == NULL || exception->status == FIFTYONE_DEGREES_STATUS_NOT_SET)
149 
150 #ifdef FIFTYONE_DEGREES_EXCEPTIONS_HPP
151 
156 #define FIFTYONE_DEGREES_EXCEPTION_THROW \
157 if (FIFTYONE_DEGREES_EXCEPTION_OKAY == false) { \
158 throw FiftyoneDegrees::Common::FatalException(exception); \
159 }
160 
161 #else
162 
166 #define FIFTYONE_DEGREES_EXCEPTION_THROW \
167 fiftyoneDegreesExceptionCheckAndExit(exception);
168 
169 #endif
170 
171 #else
172 
173 EXTERNAL typedef void* fiftyoneDegreesException;
174 
175 #define FIFTYONE_DEGREES_EXCEPTION_CLEAR exception = NULL;
176 
177 #define FIFTYONE_DEGREES_EXCEPTION_SET(s) exception = NULL;
178 
179 #define FIFTYONE_DEGREES_EXCEPTION_OKAY (exception == exception)
180 
181 #define FIFTYONE_DEGREES_EXCEPTION_THROW
182 
183 #endif
184 
188 #define FIFTYONE_DEGREES_EXCEPTION_CREATE \
189 fiftyoneDegreesException exceptionValue; \
190 fiftyoneDegreesException *exception = &exceptionValue; \
191 FIFTYONE_DEGREES_EXCEPTION_CLEAR
192 
196 #define FIFTYONE_DEGREES_EXCEPTION_FAILED \
197 (FIFTYONE_DEGREES_EXCEPTION_OKAY == false)
198 
205 EXTERNAL const char* fiftyoneDegreesExceptionGetMessage(
206  fiftyoneDegreesException *exception);
207 
214  fiftyoneDegreesException *exception);
215 
220 #endif
const char * func
Function generating the exception.
Definition: exceptions.h:118
fiftyoneDegreesStatusCode status
Status code to assign.
Definition: exceptions.h:120
fiftyoneDegreesStatusCode
Status returned from the initialisation of a resource.
Definition: status.h:82
int line
Line number generating the exception.
Definition: exceptions.h:119
void fiftyoneDegreesExceptionCheckAndExit(fiftyoneDegreesException *exception)
If the exception is set then will print a message to stderr and exit the process.
const char * file
File generating the exception.
Definition: exceptions.h:117
const char * fiftyoneDegreesExceptionGetMessage(fiftyoneDegreesException *exception)
Returns an English error message for the exception.
Structure used to represent a 51Degrees exception and passed into methods that might generate excepti...
Definition: exceptions.h:116