cheax
Lisp dialect with C API
Error handling

Error codes and ways to deal with them. More...

Collaboration diagram for Error handling:

Macros

#define ERR_NAME_PAIR(NAME)   {#NAME, CHEAX_##NAME}
 
#define CHEAX_BUILTIN_ERROR_NAMES(var)
 
#define cheax_ft(c, pad)   { if (cheax_errno(c) != 0) goto pad; }
 Macro to fall through to a pad in case of an error. More...
 

Enumerations

enum  {
  CHEAX_ENOERR = 0x0000 , CHEAX_EREAD = 0x0001 , CHEAX_EEOF = 0x0002 , CHEAX_EEVAL = 0x0101 ,
  CHEAX_ENOSYM = 0x0102 , CHEAX_ESTACK = 0x0103 , CHEAX_ETYPE = 0x0104 , CHEAX_EMATCH = 0x0105 ,
  CHEAX_ESTATIC = 0x0106 , CHEAX_EDIVZERO = 0x0107 , CHEAX_EREADONLY = 0x0108 , CHEAX_EWRITEONLY = 0x0109 ,
  CHEAX_EEXIST = 0x010A , CHEAX_EVALUE = 0x010B , CHEAX_EOVERFLOW = 0x010C , CHEAX_EINDEX = 0x010D ,
  CHEAX_EIO = 0x010E , CHEAX_EAPI = 0x0200 , CHEAX_ENOMEM = 0x0201 , CHEAX_EUSER0 = 0x0400
}
 Pre-defined cheax error codes. More...
 

Functions

int cheax_errno (CHEAX *c) CHX_PURE
 Gets the value of the current cheax error code. More...
 
void cheax_perror (CHEAX *c, const char *s)
 Prints the current cheax error code and error message. More...
 
void cheax_clear_errno (CHEAX *c)
 Sets cheax_errno() to 0. More...
 
void cheax_throw (CHEAX *c, int code, struct chx_string *msg)
 Sets cheax_errno() to the given value. More...
 
void cheax_throwf (CHEAX *c, int code, const char *fmt,...) CHX_FORMAT(printf
 
void void cheax_add_bt (CHEAX *c)
 
int cheax_new_error_code (CHEAX *c, const char *name)
 Creates a new error code with a given name. More...
 
int cheax_find_error_code (CHEAX *c, const char *name)
 Looks up the value of a named error code. More...
 

Detailed Description

Error codes and ways to deal with them.

Macro Definition Documentation

◆ ERR_NAME_PAIR

#define ERR_NAME_PAIR (   NAME)    {#NAME, CHEAX_##NAME}

◆ CHEAX_BUILTIN_ERROR_NAMES

#define CHEAX_BUILTIN_ERROR_NAMES (   var)
Value:
static const struct { const char *name; int code; } var[] = { \
ERR_NAME_PAIR(ENOERR), \
ERR_NAME_PAIR(EEVAL), ERR_NAME_PAIR(ENOSYM), \
ERR_NAME_PAIR(ESTACK), ERR_NAME_PAIR(ETYPE), \
ERR_NAME_PAIR(EMATCH), ERR_NAME_PAIR(ESTATIC), \
ERR_NAME_PAIR(EDIVZERO), ERR_NAME_PAIR(EREADONLY), \
ERR_NAME_PAIR(EWRITEONLY), ERR_NAME_PAIR(EEXIST), \
ERR_NAME_PAIR(EVALUE), ERR_NAME_PAIR(EOVERFLOW), \
ERR_NAME_PAIR(EINDEX), ERR_NAME_PAIR(EIO), \
ERR_NAME_PAIR(EAPI), ERR_NAME_PAIR(ENOMEM) \
}
#define ERR_NAME_PAIR(NAME)
Definition: cheax.h:690

◆ cheax_ft

#define cheax_ft (   c,
  pad 
)    { if (cheax_errno(c) != 0) goto pad; }

Macro to fall through to a pad in case of an error.

Jumps to pad if cheax_errno() is not 0. Most commonly used after cheax_eval().

Parameters
padLabel to jump to in case of an error.

Enumeration Type Documentation

◆ anonymous enum

anonymous enum

Pre-defined cheax error codes.

See also
cheax_errno(), cheax_throw(), cheax_new_error_code()
Enumerator
CHEAX_ENOERR 

No error. Equal to 0.

See also
cheax_clear_errno()
CHEAX_EREAD 

Generic read error.

CHEAX_EEOF 

Unexpected end-of-file.

CHEAX_EEVAL 

Generic eval error

CHEAX_ENOSYM 

Symbol not found error.

CHEAX_ESTACK 

Stack overflow error.

CHEAX_ETYPE 

Invalid type error.

CHEAX_EMATCH 

Unable to match expression error.

CHEAX_ESTATIC 

Preprocessing failed.

CHEAX_EDIVZERO 

Division by zero error.

CHEAX_EREADONLY 

Attempted write to read-only symbol error.

CHEAX_EWRITEONLY 

Attempted read from write-only symbol error.

CHEAX_EEXIST 

Symbol already exists error.

CHEAX_EVALUE 

Invalid value error.

CHEAX_EOVERFLOW 

Integer overflow error.

CHEAX_EINDEX 

Invalid index error.

CHEAX_EIO 

IO error.

CHEAX_EAPI 

API error.

Note
Not to be thrown from within cheax code.
CHEAX_ENOMEM 

Out-of-memory error.

Note
Not to be thrown from within cheax code.
CHEAX_EUSER0 

First user-defineable error code.

See also
cheax_new_error_code()

Function Documentation

◆ cheax_errno()

int cheax_errno ( CHEAX c)

Gets the value of the current cheax error code.

See also
cheax_throw(), cheax_new_error_code(), cheax_ft()

◆ cheax_perror()

void cheax_perror ( CHEAX c,
const char *  s 
)

Prints the current cheax error code and error message.

Parameters
sArgument string, will be printed followed by a colon and an error description.

◆ cheax_clear_errno()

void cheax_clear_errno ( CHEAX c)

Sets cheax_errno() to 0.

See also
cheax_errno()

◆ cheax_throw()

void cheax_throw ( CHEAX c,
int  code,
struct chx_string *  msg 
)

Sets cheax_errno() to the given value.

Sets cheax_errno() to CHEAX_EAPI if code is 0.

Parameters
codeError code.
msgError message string or NULL.
See also
cheax_errno(), cheax_clear_errno()

◆ cheax_throwf()

void cheax_throwf ( CHEAX c,
int  code,
const char *  fmt,
  ... 
)

◆ cheax_add_bt()

void void cheax_add_bt ( CHEAX c)

◆ cheax_new_error_code()

int cheax_new_error_code ( CHEAX c,
const char *  name 
)

Creates a new error code with a given name.

Such new error codes can then be thrown with cheax_throw() or from within cheax.

Does not change cheax_errno(), except when name is NULL, in which case it is set to CHEAX_EAPI.

Parameters
nameThe error code's name. Used to make the error code available in cheax, and for error reporting by cheax_perror().
Returns
The newly created error code value.

◆ cheax_find_error_code()

int cheax_find_error_code ( CHEAX c,
const char *  name 
)

Looks up the value of a named error code.

Sets cheax_errno() to CHEAX_EAPI if name is NULL.

Parameters
nameError code name.
Returns
The error code carrying the given name, or -1 if unsuccessful.