treelite
Macros | Functions
c_api_error.h File Reference

Error handling for C API. More...

#include <stdexcept>
Include dependency graph for c_api_error.h:

Go to the source code of this file.

Macros

#define API_BEGIN()   try {
 Macro to guard beginning and end section of all functions. More...
 
#define API_END()
 Every function starts with API_BEGIN(); and finishes with API_END() or API_END_HANDLE_ERROR. More...
 
#define API_END_HANDLE_ERROR(Finalize)
 Every function starts with API_BEGIN(); and finishes with API_END() or API_END_HANDLE_ERROR() "Finalize" contains procedure to cleanup states when an error happens. More...
 

Functions

void TreeliteAPISetLastError (char const *msg)
 Set the last error message needed by C API. More...
 
int TreeliteAPIHandleException (std::exception const &e)
 handle Exception thrown out More...
 

Detailed Description

Error handling for C API.

Copyright (c) 2017-2023 by Contributors

Author
Hyunsu Cho

Macro Definition Documentation

◆ API_BEGIN

#define API_BEGIN ( )    try {

Macro to guard beginning and end section of all functions.

◆ API_END

#define API_END ( )
Value:
} \
catch (std::exception & _except_) { \
return TreeliteAPIHandleException(_except_); \
} \
return 0
int TreeliteAPIHandleException(std::exception const &e)
handle Exception thrown out
Definition: c_api_error.h:45

Every function starts with API_BEGIN(); and finishes with API_END() or API_END_HANDLE_ERROR.

◆ API_END_HANDLE_ERROR

#define API_END_HANDLE_ERROR (   Finalize)
Value:
} \
catch (std::exception & _except_) { \
Finalize; \
return TreeliteAPIHandleException(_except_); \
} \
return 0

Every function starts with API_BEGIN(); and finishes with API_END() or API_END_HANDLE_ERROR() "Finalize" contains procedure to cleanup states when an error happens.

Function Documentation

◆ TreeliteAPIHandleException()

int TreeliteAPIHandleException ( std::exception const &  e)
inline

handle Exception thrown out

Parameters
eException object
Returns
The return value of API after exception is handled

◆ TreeliteAPISetLastError()

void TreeliteAPISetLastError ( char const *  msg)

Set the last error message needed by C API.

Parameters
msgError message to set.