15 #include "serialbox-c/ErrorHandling.h" 29 FatalErrorHandler = handler;
37 assert(FatalErrorHandler);
38 (*FatalErrorHandler)(reason);
46 std::fprintf(stderr,
"Serialbox: ERROR: %s\n", reason);
54 bool hasError =
false;
55 std::string errMsg =
"";
58 static ErrorState errorState;
63 internal::errorState.hasError =
true;
64 internal::errorState.errMsg = reason;
70 std::size_t size = internal::errorState.errMsg.size() + 1;
71 char* errorMessage = (
char*)std::malloc(size *
sizeof(
char));
72 std::memcpy(errorMessage, internal::errorState.errMsg.c_str(), size);
77 internal::errorState.hasError =
false;
78 internal::errorState.errMsg.clear();
void serialboxResetFatalErrorHandler(void)
Reset the fatal error handler.
int serialboxStateErrorHandlerHasError(void)
Check the current error state.
char * serialboxStateErrorHandlerGetErrorMessage(void)
Query the current error state.
void serialboxInstallFatalErrorHandler(serialboxFatalErrorHandler_t handler)
Install a fatal error handler.
void serialboxStateErrorHandler(const char *reason)
Store the the current state of the error which can be queried via serialboxStateErrorHandlerGetLastEr...
void serialboxStateErrorHandlerResetState(void)
Reset the current error state.
void serialboxFatalError(const char *reason)
Report a fatal error.
void serialboxDefaultFatalErrorHandler(const char *reason)
Emit the last error string to stderr and call exit(1)
SERIALBOX_API typedef void(* serialboxFatalErrorHandler_t)(const char *reason)
Error handler callback.