-
-
Notifications
You must be signed in to change notification settings - Fork 203
Error handling in C
Szabolcs Horvát edited this page Dec 30, 2023
·
1 revision
Handling error codes must be done differently depending on where the error occurs. There are two types of C functions in R/igraph:
- Those which are called from C only (never directly from R using
.Call
). If an error may occur in these functions, they must return anigraph_error_t
. These functions may be called from each other. These function must check for error codes usingIGRAPH_CHECK()
. These functions must report errors using the standardIGRAPH_ERROR()
andIGRAPH_ERRORF()
macros, which in turn calligraph_error()
/igraph_errorf()
. When the error handler is invoked from these functions, it will return. - 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 avoid
return type. Top-level functions must useIGRAPH_R_CHECK()
to handle error codes returned by other C functions. They may report errors using the standardIGRAPH_ERROR()
andIGRAPH_ERRORF()
macros, which in turn calligraph_error()
/igraph_errorf()
. When the error handler is invoked from these functions, it will not return.