\r\n

51Degrees Device Detection C/C++  4.5

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 2023 51 Degrees Mobile Experts Limited, Davidson House,
4  * Forbury Square, Reading, Berkshire, United Kingdom RG1 3EU.
5  *
6  * This Original Work is licensed under the European Union Public Licence
7  * (EUPL) 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 { \
135 exception->file = NULL; \
136 exception->func = NULL; \
137 exception->line = -1; \
138 exception->status = FIFTYONE_DEGREES_STATUS_NOT_SET; \
139 }
140 
147 #define FIFTYONE_DEGREES_EXCEPTION_CHECK(t) \
148 (exception == NULL || exception->status == t)
149 
153 #define FIFTYONE_DEGREES_EXCEPTION_OKAY \
154 FIFTYONE_DEGREES_EXCEPTION_CHECK(FIFTYONE_DEGREES_STATUS_NOT_SET)
155 
156 #ifdef FIFTYONE_DEGREES_EXCEPTIONS_HPP
157 
162 #define FIFTYONE_DEGREES_EXCEPTION_THROW \
163 if (FIFTYONE_DEGREES_EXCEPTION_OKAY == false) { \
164 throw FiftyoneDegrees::Common::FatalException(exception); \
165 }
166 
167 #else
168 
172 #define FIFTYONE_DEGREES_EXCEPTION_THROW \
173 fiftyoneDegreesExceptionCheckAndExit(exception);
174 
175 #endif
176 
177 #else
178 
179 EXTERNAL typedef void* fiftyoneDegreesException;
180 
181 #define FIFTYONE_DEGREES_EXCEPTION_CLEAR
182 
183 #define FIFTYONE_DEGREES_EXCEPTION_SET(s)
184 
185 #define FIFTYONE_DEGREES_EXCEPTION_OKAY true
186 
187 #define FIFTYONE_DEGREES_EXCEPTION_THROW
188 
189 #define FIFTYONE_DEGREES_EXCEPTION_CHECK(t) false
190 
191 #endif
192 
196 #define FIFTYONE_DEGREES_EXCEPTION_CREATE \
197 fiftyoneDegreesException exceptionValue; \
198 fiftyoneDegreesException *exception = &exceptionValue; \
199 FIFTYONE_DEGREES_EXCEPTION_CLEAR
200 
204 #define FIFTYONE_DEGREES_EXCEPTION_FAILED \
205 (FIFTYONE_DEGREES_EXCEPTION_OKAY == false)
206 
213 EXTERNAL const char* fiftyoneDegreesExceptionGetMessage(
214  fiftyoneDegreesException *exception);
215 
222  fiftyoneDegreesException *exception);
223 
228 #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