Medial Code Documentation
Loading...
Searching...
No Matches
c_api_error.h
Go to the documentation of this file.
1
6#ifndef XGBOOST_C_API_C_API_ERROR_H_
7#define XGBOOST_C_API_C_API_ERROR_H_
8
9#include <dmlc/base.h>
10#include <dmlc/logging.h>
11
12#include "c_api_utils.h"
13
15#ifdef LOG_CAPI_INVOCATION
16#define API_BEGIN() \
17 LOG(CONSOLE) << "[XGBoost C API invocation] " << __PRETTY_FUNCTION__; \
18 try { \
19 auto __guard = ::xgboost::XGBoostAPIGuard();
20#else // LOG_CAPI_INVOCATION
21#define API_BEGIN() \
22 try { \
23 auto __guard = ::xgboost::XGBoostAPIGuard();
24
25#define API_BEGIN_UNGUARD() try {
26#endif // LOG_CAPI_INVOCATION
27
30#define API_END() \
31 } catch (dmlc::Error & _except_) { \
32 return XGBAPIHandleException(_except_); \
33 } catch (std::exception const &_except_) { \
34 return XGBAPIHandleException(dmlc::Error(_except_.what())); \
35 } \
36 return 0; // NOLINT(*)
37
38#define CHECK_HANDLE() if (handle == nullptr) \
39 LOG(FATAL) << "DMatrix/Booster has not been initialized or has already been disposed.";
40
45void XGBAPISetLastError(const char* msg);
51inline int XGBAPIHandleException(const dmlc::Error &e) {
52 XGBAPISetLastError(e.what());
53 return -1;
54}
55
56#define xgboost_CHECK_C_ARG_PTR(out_ptr) \
57 do { \
58 if (XGBOOST_EXPECT(!(out_ptr), false)) { \
59 LOG(FATAL) << "Invalid pointer argument: " << #out_ptr; \
60 } \
61 } while (0)
62
63#endif // XGBOOST_C_API_C_API_ERROR_H_
void XGBAPISetLastError(const char *msg)
Set the last error message needed by C API.
Definition c_api_error.cc:20
int XGBAPIHandleException(const dmlc::Error &e)
handle exception thrown out
Definition c_api_error.h:51
defines configuration macros
defines logging macros of dmlc allows use of GLOG, fall back to internal implementation when disabled
exception class that will be thrown by default logger if DMLC_LOG_FATAL_THROW == 1
Definition logging.h:29