\r\n

51Degrees Device Detection C/C++  4.4

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 #include "common.h"
101 
102 #ifndef FIFTYONE_DEGREES_EXCEPTIONS_DISABLED
103 
111 EXTERNAL typedef struct fiftyone_degrees_exception_t {
112  const char *file;
113  const char *func;
114  int line;
117 
122 #define FIFTYONE_DEGREES_EXCEPTION_SET(s) \
123 if (exception != NULL) { \
124 exception->file = __FILE__; \
125 exception->func = __func__; \
126 exception->line = __LINE__; \
127 exception->status = s; \
128 }
129 
133 #define FIFTYONE_DEGREES_EXCEPTION_CLEAR \
134 exception->file = NULL; \
135 exception->func = NULL; \
136 exception->line = -1; \
137 exception->status = FIFTYONE_DEGREES_STATUS_NOT_SET;
138 
142 #define FIFTYONE_DEGREES_EXCEPTION_OKAY \
143 (exception == NULL || exception->status == FIFTYONE_DEGREES_STATUS_NOT_SET)
144 
145 #ifdef FIFTYONE_DEGREES_EXCEPTIONS_HPP
146 
151 #define FIFTYONE_DEGREES_EXCEPTION_THROW \
152 if (FIFTYONE_DEGREES_EXCEPTION_OKAY == false) { \
153 throw FiftyoneDegrees::Common::FatalException(exception); \
154 }
155 
156 #else
157 
161 #define FIFTYONE_DEGREES_EXCEPTION_THROW \
162 fiftyoneDegreesExceptionCheckAndExit(exception);
163 
164 #endif
165 
166 #else
167 
168 EXTERNAL typedef void* fiftyoneDegreesException;
169 
170 #define FIFTYONE_DEGREES_EXCEPTION_CLEAR exception = NULL;
171 
172 #define FIFTYONE_DEGREES_EXCEPTION_SET(s) exception = NULL;
173 
174 #define FIFTYONE_DEGREES_EXCEPTION_OKAY (exception == exception)
175 
176 #define FIFTYONE_DEGREES_EXCEPTION_THROW
177 
178 #endif
179 
183 #define FIFTYONE_DEGREES_EXCEPTION_CREATE \
184 fiftyoneDegreesException exceptionValue; \
185 fiftyoneDegreesException *exception = &exceptionValue; \
186 FIFTYONE_DEGREES_EXCEPTION_CLEAR
187 
191 #define FIFTYONE_DEGREES_EXCEPTION_FAILED \
192 (FIFTYONE_DEGREES_EXCEPTION_OKAY == false)
193 
200 EXTERNAL const char* fiftyoneDegreesExceptionGetMessage(
201  fiftyoneDegreesException *exception);
202 
209  fiftyoneDegreesException *exception);
210 
215 #endif
const char * func
Function generating the exception.
Definition: exceptions.h:113
fiftyoneDegreesStatusCode status
Status code to assign.
Definition: exceptions.h:115
fiftyoneDegreesStatusCode
Status returned from the initialisation of a resource.
Definition: status.h:77
int line
Line number generating the exception.
Definition: exceptions.h:114
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:112
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:111