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 2026 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
26#ifdef FIFTYONE_DEGREES_IPI_SYMBOLS
27#include "ipiSymbols.h"
28#endif
29
102
103#include "status.h"
104#include "common.h"
105
106#ifndef FIFTYONE_DEGREES_EXCEPTIONS_DISABLED
107
115EXTERNAL typedef struct fiftyone_degrees_exception_t {
116 const char *file;
117 const char *func;
118 int line;
121
126#define FIFTYONE_DEGREES_EXCEPTION_SET(s) \
127if (exception != NULL) { \
128exception->file = __FILE__; \
129exception->func = __func__; \
130exception->line = __LINE__; \
131exception->status = s; \
132}
133
137#define FIFTYONE_DEGREES_EXCEPTION_CLEAR \
138{ \
139exception->file = NULL; \
140exception->func = NULL; \
141exception->line = -1; \
142exception->status = FIFTYONE_DEGREES_STATUS_NOT_SET; \
143}
144
151#define FIFTYONE_DEGREES_EXCEPTION_CHECK(t) \
152(exception == NULL || exception->status == t)
153
157#define FIFTYONE_DEGREES_EXCEPTION_OKAY \
158FIFTYONE_DEGREES_EXCEPTION_CHECK(FIFTYONE_DEGREES_STATUS_NOT_SET)
159
160#ifdef FIFTYONE_DEGREES_EXCEPTIONS_HPP
161
166#define FIFTYONE_DEGREES_EXCEPTION_THROW \
167if (FIFTYONE_DEGREES_EXCEPTION_OKAY == false) { \
168throw FiftyoneDegrees::Common::FatalException(exception); \
169}
170
171#else
172
176#define FIFTYONE_DEGREES_EXCEPTION_THROW \
177fiftyoneDegreesExceptionCheckAndExit(exception);
178
179#endif
180
181#else
182
183EXTERNAL typedef void* fiftyoneDegreesException;
184
185#define FIFTYONE_DEGREES_EXCEPTION_CLEAR
186
187#define FIFTYONE_DEGREES_EXCEPTION_SET(s)
188
189#define FIFTYONE_DEGREES_EXCEPTION_OKAY true
190
191#define FIFTYONE_DEGREES_EXCEPTION_THROW
192
193#define FIFTYONE_DEGREES_EXCEPTION_CHECK(t) false
194
195#endif
196
200#define FIFTYONE_DEGREES_EXCEPTION_CREATE \
201fiftyoneDegreesException exceptionValue; \
202fiftyoneDegreesException *exception = &exceptionValue; \
203FIFTYONE_DEGREES_EXCEPTION_CLEAR
204
208#define FIFTYONE_DEGREES_EXCEPTION_FAILED \
209(FIFTYONE_DEGREES_EXCEPTION_OKAY == false)
210
221 fiftyoneDegreesException *exception);
222
229 fiftyoneDegreesException *exception);
230
234
235#endif
void fiftyoneDegreesExceptionCheckAndExit(fiftyoneDegreesException *exception)
If the exception is set then will print a message to stderr and exit the process.
const char * fiftyoneDegreesExceptionGetMessage(fiftyoneDegreesException *exception)
Returns an English error message for the exception.
fiftyoneDegreesStatusCode
Status returned from the initialisation of a resource.
Definition status.h:81
Structure used to represent a 51Degrees exception and passed into methods that might generate excepti...
Definition exceptions.h:115
const char * file
File generating the exception.
Definition exceptions.h:116
const char * func
Function generating the exception.
Definition exceptions.h:117
int line
Line number generating the exception.
Definition exceptions.h:118
fiftyoneDegreesStatusCode status
Status code to assign.
Definition exceptions.h:119