Turi Create
4.0
capi_error_handling.hpp
1
/* Copyright © 2018 Apple Inc. All rights reserved.
2
*
3
* Use of this source code is governed by a BSD-3-clause license that can
4
* be found in the LICENSE.txt file or at https://opensource.org/licenses/BSD-3-Clause
5
*/
6
#ifndef TURI_CAPI_ERROR_HANDLING_INTERNAL
7
#define TURI_CAPI_ERROR_HANDLING_INTERNAL
8
9
#include <capi/impl/capi_wrapper_structs.hpp>
10
#include <exception>
11
#include <string>
12
13
14
/** Define the start of the exception handling block.
15
*
16
*/
17
#define ERROR_HANDLE_START() \
18
try { do {} while(false)
19
20
21
/** Defines the end of the exception handling block.
22
*
23
* Takes one required and one option argument. First argument is the
24
* name of the tc_error** variable. Second argument is the return value
25
* on error.
26
*/
27
#define ERROR_HANDLE_END(error_var, ...) \
28
} catch(...) { \
29
fill_error_from_exception(std::current_exception(), error_var); \
30
return __VA_ARGS__; \
31
} do{} while(false)
32
33
#define CHECK_NOT_NULL(error_var, var, name, ...) \
34
do { \
35
if (var == NULL) { \
36
set_error(error_var, #name " is null."); \
37
return __VA_ARGS__; \
38
} \
39
} while (false)
40
41
42
43
// Fill error from a thrown exception
44
void
fill_error_from_exception(std::exception_ptr eptr, tc_error** error);
45
46
47
// Fill the error from an error string
48
void
set_error(tc_error** error,
const
std::string& message);
49
50
51
#endif
capi
impl
capi_error_handling.hpp
Generated by
1.8.13