forked from dmlc/dgl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathruntime_base.h
47 lines (42 loc) · 1.46 KB
/
runtime_base.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/**
* Copyright (c) 2016 by Contributors
* @file runtime_base.h
* @brief Base of all C APIs
*/
#ifndef DGL_RUNTIME_RUNTIME_BASE_H_
#define DGL_RUNTIME_RUNTIME_BASE_H_
#include <dgl/runtime/c_runtime_api.h>
#include <stdexcept>
/** @brief macro to guard beginning and end section of all functions */
#define API_BEGIN() try {
/** @brief every function starts with API_BEGIN();
and finishes with API_END() or API_END_HANDLE_ERROR */
#define API_END() \
} \
catch (std::runtime_error & _except_) { \
return DGLAPIHandleException(_except_); \
} \
return 0; // NOLINT(*)
/**
* @brief every function starts with API_BEGIN();
* and finishes with API_END() or API_END_HANDLE_ERROR
* The finally clause contains procedure to cleanup states when an error
* happens.
*/
#define API_END_HANDLE_ERROR(Finalize) \
} \
catch (std::runtime_error & _except_) { \
Finalize; \
return DGLAPIHandleException(_except_); \
} \
return 0; // NOLINT(*)
/**
* @brief handle exception throwed out
* @param e the exception
* @return the return value of API after exception is handled
*/
inline int DGLAPIHandleException(const std::runtime_error &e) {
DGLAPISetLastError(e.what());
return -1;
}
#endif // DGL_RUNTIME_RUNTIME_BASE_H_