Error Subsystem

Overview

This section describes types and facilities for setting and retrieving error information. More…

#include <jnc_Error.h>

// structs

struct jnc_Error;

// global functions

void
jnc_setErrorRouter(jnc_ErrorRouter* router);

const jnc_Error*
jnc_getLastError();

void
jnc_setError(const jnc_Error* error);

void
jnc_setErrno(int code);

void
jnc_setStringError(const char* string);

const char*
jnc_getErrorDescription_v(const jnc_Error* error);

static
const char*
jnc_getLastErrorDescription_v();

Detailed Documentation

This section describes types and facilities for setting and retrieving error information.

Global Functions

const jnc_Error*
jnc_getLastError()

Returns a pointer to the last error set in the context of the current thread.

void
jnc_setError(const jnc_Error* error)

void
jnc_setErrno(int code)

void
jnc_setStringError(const char* string)

These functions set the last error to the TLS buffer of the current thread.

  • jnc_setError sets Jancy jnc_Error pointed to by error;

  • jnc_setErrno sets POSIX errno identifed by code;

  • jnc_setStringError sets string error described by a null-terminated string pointed to by string.

const char*
jnc_getErrorDescription_v(const jnc_Error* error)

static
const char*
jnc_getLastErrorDescription_v()

Creates and returns a human-readable description of the error.

Suffix _v is used to denote the volatile nature of the returned pointer. The buffer will be overwritten by the very next call to any _v function invoked in the same thread. Do NOT save it to be re-used later; copy it to some buffer if it’s necessary.

jnc_getLastErrorDescription_v is equivalent to:

jnc_getErrorDescription_v(jnc_getLastError())

Sample:

// try to compile some Jancy code, and it fails...

printf("error: %s\n", jnc_getLastErrorDescription_v ());