Skip to content

Error handling in C

Szabolcs Horvát edited this page Dec 30, 2023 · 1 revision

Error handling in C

Handling error codes must be done differently depending on where the error occurs. There are two types of C functions in R/igraph:

  1. Those which are called from C only (never directly from R using .Call). If an error may occur in these functions, they must return an igraph_error_t. These functions may be called from each other. These function must check for error codes using IGRAPH_CHECK(). These functions must report errors using the standard IGRAPH_ERROR() and IGRAPH_ERRORF() macros, which in turn call igraph_error() / igraph_errorf(). When the error handler is invoked from these functions, it will return.
  2. Those which are called from R only (using .Call), but never from C. Let us call these "top-level C functions". Top-level functions may call other C function, but they must not be called from C. For this reason, these functions must have a void return type. Top-level functions must use IGRAPH_R_CHECK() to handle error codes returned by other C functions. They may report errors using the standard IGRAPH_ERROR() and IGRAPH_ERRORF() macros, which in turn call igraph_error() / igraph_errorf(). When the error handler is invoked from these functions, it will not return.
Clone this wiki locally