Adaptive Framework  0.9.0
All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
Files | Data Structures | Macros | Typedefs | Functions

Files

file  afw_error.h
 Adaptive Framework error handling header.
 

Data Structures

struct  afw_error_context_s
 Adaptive Framework Error Context. More...
 
struct  afw_error_s
 Adaptive Framework Error. More...
 
struct  afw_error_footprint_s
 error footprint More...
 
struct  afw_try_s
 

Macros

#define AFW_ERROR_RV_SOURCE_ID_Z_NULL   NULL
 Not applicable rv source id.
 
#define AFW_ERROR_RV_SOURCE_ID_Z_apr   "apr"
 APR rv source id. More...
 
#define AFW_ERROR_RV_SOURCE_ID_Z_icu   "icu"
 ICU rv source id. More...
 
#define AFW_ERROR_CLEAR_PARTIAL(__ERROR_)
 
#define AFW_ERROR_FOOTPRINT(_footprint_)
 Set error footprint. More...
 
#define AFW_THROW_UNHANDLED_ERROR(unhandled_error, _ERROR, _CODE, _RV_SOURCE_ID, _RV, _MESSAGE_Z)
 
#define AFW_SUCCESS(__ERROR_)   ((__ERROR_)->code == afw_error_code_none)
 
#define AFW_ERROR_OCCURRED(__ERROR_)   ((__ERROR_)->code != afw_error_code_none)
 
#define AFW_THROW(xctx)    longjmp(((xctx)->current_try->throw_jmp_buf), (xctx)->error->code)
 
#define AFW_THROW_ERROR_Z(code, message_z, xctx)
 Macro used to set error and 0 rv in xctx and throw it. More...
 
#define AFW_THROW_ERROR_RV_Z(code, rv_source_id, rv, message_z, xctx)
 Macro used to set error and rv in xctx and throw it. More...
 
#define AFW_THROW_ERROR_FZ(code, xctx, format_z, ...)
 Macro used to set error and 0 rv in xctx and throw it. More...
 
#define AFW_THROW_ERROR_RV_FZ(code, rv_source_id, rv, xctx, format_z, ...)
 Macro used to set error and rv in xctx and throw it. More...
 
#define AFW_THROW_ERROR_VZ(code, format_z, ap, xctx)
 Macro used to set error and 0 rv in xctx and throw it. More...
 
#define AFW_THROW_ERROR_RV_VZ(code, rv_source_id, rv, format_z, ap, xctx)
 Macro used to set error and rv in xctx and throw it. More...
 
#define AFW_THROW_ERROR_FOOTPRINT_Z(code, message_z, xctx)
 Macro used to set error and 0 rv in xctx using line number in footprint then throw it. More...
 
#define AFW_THROW_ERROR_FOOTPRINT_RV_Z(code, rv_source_id, rv, message_z, xctx)
 Macro used to set error and rv in xctx using line number in footprint then throw it. More...
 
#define AFW_THROW_ERROR_FOOTPRINT_FZ(code, xctx, format_z, ...)
 Macro used to set error and 0 rv in xctx using line number in footprint then throw it. More...
 
#define AFW_THROW_ERROR_FOOTPRINT_RV_FZ(code, rv_source_id, rv, xctx, format_z, ...)
 Macro used to set error and rv in xctx using line number in footprint then throw it. More...
 
#define AFW_THROW_ERROR_FOOTPRINT_VZ(code, format_z, ap, xctx)
 Macro used to set error and 0 rv in xctx using line number in footprint then throw it. More...
 
#define AFW_THROW_ERROR_FOOTPRINT_RV_VZ(code, rv_source_id, rv, format_z, ap, xctx)
 Macro used to set error and rv in xctx using line number in footprint then throw it. More...
 
#define AFW_THROW_MEMORY_ERROR(xctx)
 
#define AFW_ERROR_INTERNAL_ON_UNHANDLED(__TRY_)
 
#define AFW_ERROR_COPY(to, from)
 Copy an error struct. More...
 
#define AFW_ERROR_THROWN   ((const afw_error_t *)&this_THROWN_ERROR)
 Access the thrown error. See AFW_TRY. More...
 
#define AFW_TRY
 Begin an AFW TRY block. More...
 
#define AFW_CATCH(__CODE_)
 Catch a particular error that occurs in a AFW_TRY block. More...
 
#define AFW_CATCH_UNHANDLED
 Catch an unhandled error that occurs in a AFW_TRY block. More...
 
#define AFW_FINALLY
 Always executed regardless of error. More...
 
#define AFW_ENDTRY
 Ends an AFW try block. More...
 
#define AFW_MARK_UNHANDLED
 Use in an AFW_CATCH or AFW_CATCH_UNHANDLED block to mark error as unhandled and break. More...
 
#define afw_error_source_file(error)    afw_utf8_z_source_file((error)->source_z)
 Returns value of error->source_z after last '/ 'or '\'. More...
 

Typedefs

typedef struct afw_error_footprint_s afw_error_footprint_t
 error footprint More...
 

Functions

void afw_error_rv_set_z (afw_error_code_t code, const afw_utf8_z_t *rv_source_id_z, int related_rv, const afw_utf8_z_t *source_z, const afw_utf8_z_t *message_z, afw_xctx_t *xctx)
 
void afw_error_set_z (afw_error_code_t code, const afw_utf8_z_t *source_z, const afw_utf8_z_t *message_z, afw_xctx_t *xctx)
 
void afw_error_rv_set_fz (afw_error_code_t code, const afw_utf8_z_t *rv_source_id_z, int related_rv, const afw_utf8_z_t *source_z, afw_xctx_t *xctx, const afw_utf8_z_t *format_z,...)
 
void afw_error_set_fz (afw_error_code_t code, const afw_utf8_z_t *source_z, afw_xctx_t *xctx, const afw_utf8_z_t *format_z,...)
 
void afw_error_rv_set_vz (afw_error_code_t code, const afw_utf8_z_t *rv_source_id_z, int related_rv, const afw_utf8_z_t *source_z, const afw_utf8_z_t *format_z, va_list ap, afw_xctx_t *xctx)
 
void afw_error_set_vz (afw_error_code_t code, const afw_utf8_z_t *source_z, const afw_utf8_z_t *format_z, va_list ap, afw_xctx_t *xctx)
 
const afw_object_tafw_error_to_object (const afw_error_t *error, const afw_pool_t *p, afw_xctx_t *xctx)
 Create an object with error info in specified pool. More...
 
void afw_error_add_to_object (const afw_object_t *object, const afw_error_t *error, afw_xctx_t *xctx)
 Add error info to existing object using specified pool. More...
 
afw_boolean_t afw_error_allow_in_response (afw_error_code_t code)
 Determine if the error object for code is allowed in HTTP response. More...
 
int afw_error_print (FILE *fp, const afw_error_t *error)
 Print error. More...
 
int afw_error_print_with_xctx (FILE *fp, const afw_error_t *error, const afw_pool_t *p, afw_xctx_t *xctx)
 Print error when xctx is available. More...
 
void afw_error_write_log (afw_log_priority_t priority, const afw_error_t *error, afw_xctx_t *xctx)
 Write error to environment log. More...
 
const afw_utf8_z_tafw_error_message (afw_xctx_t *xctx, const afw_utf8_z_t *format,...)
 Build message in xctx error message_wa and return pointer. More...
 
const afw_utf8_z_tafw_error_message_vz (const afw_utf8_z_t *format, va_list ap, afw_xctx_t *xctx)
 Build message in xctx error message_wa and return pointer. More...
 
 afw_error_http_status (const afw_error_t *error)
 Returns http status for error. More...
 
const afw_utf8_z_tafw_error_code_id_z (const afw_error_t *error)
 Returns error->code id. More...
 
const afw_utf8_tafw_error_to_utf8 (const afw_error_t *error, const afw_pool_t *p, afw_xctx_t *xctx)
 Convert error to utf8. More...
 

Detailed Description

Adaptive Framework error

Typedef afw_error_code_t is defined in afw_common.h

Macro Definition Documentation

◆ AFW_CATCH

#define AFW_CATCH (   __CODE_)
Value:
while(0); \
break; \
} \
if (xctx->error->code == (afw_error_code_ ## __CODE_)) \
{ \
this_ERROR_CAUGHT = true; \
do

Catch a particular error that occurs in a AFW_TRY block.

The xctx's current_try is set to its value before entering the AFW_TRY block, so errors thrown in this AFW_CATCH block will be handle by the previous try;

Definition at line 668 of file afw_error.h.

◆ AFW_CATCH_UNHANDLED

#define AFW_CATCH_UNHANDLED
Value:
while(0); \
break; \
} \
{ \
this_ERROR_CAUGHT = true; \
do

Catch an unhandled error that occurs in a AFW_TRY block.

The xctx's current_try is set to its value before entering the AFW_TRY block, so errors thrown in this AFW_CATCH_UNHANDLED block will be handle by the previous try;

Definition at line 684 of file afw_error.h.

◆ AFW_ENDTRY

#define AFW_ENDTRY
Value:
while(0); \
} \
} while(0); \
xctx->current_try = this_TRY.prev; \
if (this_ERROR_OCCURRED && !this_ERROR_CAUGHT) { \
AFW_ERROR_COPY(xctx->error, &this_THROWN_ERROR); \
longjmp(xctx->current_try->throw_jmp_buf, this_THROWN_ERROR.code); \
}\
xctx->evaluation_stack->top = xctx->evaluation_stack->first + \
this_TOP_OFFSET; \
} while (0)

Ends an AFW try block.

Ends a TRY bock. If error was not handled, it will be rethrown so previous try can hand it. If error was handled, the xctx's error is cleared.

The xctx's current_try is set to its value before entering the AFW_TRY block, so errors thrown after this AFW_ENDTRY block will be handle by the previous try;

Always follow AFW_ENDTRY with a semicolon.

Definition at line 727 of file afw_error.h.

◆ AFW_ERROR_CLEAR_PARTIAL

#define AFW_ERROR_CLEAR_PARTIAL (   __ERROR_)
Value:
memset( \
(char *)&((__ERROR_)->code), \
0, \
( \
(char *)&((__ERROR_)->decode_rv_wa[0]) - \
(char *)&((__ERROR_)->code) \
) \
);
Todo:
FIXME: AFW_MARK_UNHANDLED doesn't restore evaluation_stack.

Definition at line 138 of file afw_error.h.

◆ AFW_ERROR_COPY

#define AFW_ERROR_COPY (   to,
  from 
)
Value:
memcpy((to), (from), sizeof(afw_error_t)); \
if ((from)->message_z == &(from)->message_wa[0]) { \
(to)->message_z = &(to)->message_wa[0]; \
} \
if ((from)->rv_decoded_z == &(from)->decode_rv_wa[0]) { \
(to)->rv_decoded_z = &(to)->decode_rv_wa[0]; \
}
Adaptive Framework Error.
Definition: afw_error.h:65

Copy an error struct.

Parameters
tomust be sizeof(afw_error_t)
fromis address of error to copy.

The from error struct is copied to to and the to->message_z and to->rv_decoded_z is adjusted if they point to the corresponding wa in from.

Definition at line 539 of file afw_error.h.

◆ AFW_ERROR_FOOTPRINT

#define AFW_ERROR_FOOTPRINT (   _footprint_)
Value:
footprint.z = _footprint_; \
footprint.source_z = AFW__FILE_LINE__;
#define AFW__FILE_LINE__
file:line
Definition: afw_common.h:148

Set error footprint.

Parameters
<em>footprint</em>is a afw_u8z_z literal associated with footprint

This macro will set footprint.z to footprint and footprint.source_z to AFW__FILE_LINE__.

Variable with the specific name footprint of type afw_error_footprint_t must already be defined.

afw_error_footprint_t footprint;

Definition at line 171 of file afw_error.h.

◆ AFW_ERROR_INTERNAL_ON_UNHANDLED

#define AFW_ERROR_INTERNAL_ON_UNHANDLED (   __TRY_)
Value:
(__TRY_).prev = NULL;\
if ((setjmp((__TRY_).throw_jmp_buf)) != 0)

Definition at line 525 of file afw_error.h.

◆ AFW_ERROR_OCCURRED

#define AFW_ERROR_OCCURRED (   __ERROR_)    ((__ERROR_)->code != afw_error_code_none)

Macro used to test if error->code is not afw_error_code_none.

This macro should normally only be used when an xctx is not available. AFW_THROW related macros should be used instead.

Definition at line 208 of file afw_error.h.

◆ AFW_ERROR_RV_SOURCE_ID_Z_apr

#define AFW_ERROR_RV_SOURCE_ID_Z_apr   "apr"

APR rv source id.

Registered in afw_environment_register_core.c.

Definition at line 40 of file afw_error.h.

◆ AFW_ERROR_RV_SOURCE_ID_Z_icu

#define AFW_ERROR_RV_SOURCE_ID_Z_icu   "icu"

ICU rv source id.

Registered in afw_environment_register_core.c.

Definition at line 47 of file afw_error.h.

◆ afw_error_source_file

#define afw_error_source_file (   error)     afw_utf8_z_source_file((error)->source_z)

Returns value of error->source_z after last '/ 'or '\'.

Parameters
errorstruct;
Returns
pointer past last '/' or '\'.

Some compilers return the full path name for FILE, but we normally just want to display the part of path after last slash.

Definition at line 879 of file afw_error.h.

◆ AFW_ERROR_THROWN

#define AFW_ERROR_THROWN   ((const afw_error_t *)&this_THROWN_ERROR)

Access the thrown error. See AFW_TRY.

This should only be called in the body of AFW_CATCH and AFW_CATCH_UNHANDLED.

Definition at line 554 of file afw_error.h.

◆ AFW_FINALLY

#define AFW_FINALLY
Value:
while(0); \
} \
} while(0); \
do { \
if (this_FINALLY_ENTERED) { \
this_THROWN_ERROR.recursive_error_in_finally = true; \
break; \
} \
this_FINALLY_ENTERED = true; \
{ \
do

Always executed regardless of error.

The body of AFW_FINALLY is executed after the body of the AFW_TRY and bodies of AFW_CATCH* macros, regardless of whether an error has occurred.

The xctx's current_try is set to its value before entering the AFW_TRY block, so errors thrown in this AFW_FINALLY block will be handle by the previous try;

Definition at line 702 of file afw_error.h.

◆ AFW_MARK_UNHANDLED

#define AFW_MARK_UNHANDLED
Value:
this_ERROR_CAUGHT = false; \
break;

Use in an AFW_CATCH or AFW_CATCH_UNHANDLED block to mark error as unhandled and break.

The AFW_ENDTRY will rethrow the error.

Always follow with a semicolon (AFW_MARK_UNHANDLED;).

Definition at line 750 of file afw_error.h.

◆ AFW_SUCCESS

#define AFW_SUCCESS (   __ERROR_)    ((__ERROR_)->code == afw_error_code_none)

Macro used to test if error->code is afw_error_code_none.

This macro should normally only be used when an xctx is not available. AFW_THROW related macros should be used instead.

Definition at line 200 of file afw_error.h.

◆ AFW_THROW

#define AFW_THROW (   xctx)     longjmp(((xctx)->current_try->throw_jmp_buf), (xctx)->error->code)

Macro used to throw an error. The error should already be set using macro AFW_SET_ERROR().

Always follow with a semicolon ( AFW_THROW(xctx); ).

Definition at line 271 of file afw_error.h.

◆ AFW_THROW_ERROR_FOOTPRINT_FZ

#define AFW_THROW_ERROR_FOOTPRINT_FZ (   code,
  xctx,
  format_z,
  ... 
)
Value:
do { \
afw_error_set_fz(afw_error_code_ ## code, \
footprint.source_z, xctx, format_z, __VA_ARGS__); \
longjmp(((xctx)->current_try->throw_jmp_buf), (afw_error_code_ ## code)); \
} while (0)

Macro used to set error and 0 rv in xctx using line number in footprint then throw it.

Parameters
codeto be appended to afw_error_code_
line_numberof footprint
xctxof caller.
format_zformat for error message
...for format_z

Always follow with a semicolon;

Definition at line 428 of file afw_error.h.

◆ AFW_THROW_ERROR_FOOTPRINT_RV_FZ

#define AFW_THROW_ERROR_FOOTPRINT_RV_FZ (   code,
  rv_source_id,
  rv,
  xctx,
  format_z,
  ... 
)
Value:
do { \
afw_error_rv_set_fz(afw_error_code_ ## code, \
AFW_ERROR_RV_SOURCE_ID_Z_ ## rv_source_id, rv, \
footprint.source_z, xctx, format_z, __VA_ARGS__); \
longjmp(((xctx)->current_try->throw_jmp_buf), (afw_error_code_ ## code)); \
} while (0)

Macro used to set error and rv in xctx using line number in footprint then throw it.

Parameters
codeto be appended to afw_error_code_
line_numberof footprint
rv_source_idto append to AFW_ERROR_RV_SOURCE_ID_Z_
rvassociated with rv_source_id
xctxof caller.
format_zformat for error message
...for format_z

Always follow with a semicolon;

Definition at line 449 of file afw_error.h.

◆ AFW_THROW_ERROR_FOOTPRINT_RV_VZ

#define AFW_THROW_ERROR_FOOTPRINT_RV_VZ (   code,
  rv_source_id,
  rv,
  format_z,
  ap,
  xctx 
)
Value:
do { \
afw_error_rv_set_vz(afw_error_code_ ## code, \
AFW_ERROR_RV_SOURCE_ID_Z_ ## rv_source_id, rv, \
footprint.source_z, format_z, ap, xctx); \
longjmp(((xctx)->current_try->throw_jmp_buf), (afw_error_code_ ## code)); \
} while (0)

Macro used to set error and rv in xctx using line number in footprint then throw it.

Parameters
codeto be appended to afw_error_code_
line_numberof footprint
rv_source_idto append to AFW_ERROR_RV_SOURCE_ID_Z_
rvassociated with rv_source_id
format_zformat for error message
aparguments for format_z
xctxof caller.

Definition at line 486 of file afw_error.h.

◆ AFW_THROW_ERROR_FOOTPRINT_RV_Z

#define AFW_THROW_ERROR_FOOTPRINT_RV_Z (   code,
  rv_source_id,
  rv,
  message_z,
  xctx 
)
Value:
do { \
afw_error_rv_set_z(afw_error_code_ ## code, \
AFW_ERROR_RV_SOURCE_ID_Z_ ## rv_source_id, rv, \
footprint.source_z, message_z, xctx); \
longjmp(((xctx)->current_try->throw_jmp_buf), (afw_error_code_ ## code)); \
} while (0)

Macro used to set error and rv in xctx using line number in footprint then throw it.

Parameters
codeto be appended to afw_error_code_
line_numberof footprint
rv_source_idto append to AFW_ERROR_RV_SOURCE_ID_Z_
rvassociated with rv_source_id_z
message_zerror message.
xctxof caller.

Always follow with a semicolon;

Definition at line 408 of file afw_error.h.

◆ AFW_THROW_ERROR_FOOTPRINT_VZ

#define AFW_THROW_ERROR_FOOTPRINT_VZ (   code,
  format_z,
  ap,
  xctx 
)
Value:
do { \
afw_error_set_vz(afw_error_code_ ## code, \
footprint.source_z, format_z, ap, xctx); \
longjmp(((xctx)->current_try->throw_jmp_buf), (afw_error_code_ ## code)); \
} while (0)

Macro used to set error and 0 rv in xctx using line number in footprint then throw it.

Parameters
codeto be appended to afw_error_code_
line_numberof footprint
format_zformat for error message
aparguments for format_z
xctxof caller.

Always follow with a semicolon;

Definition at line 468 of file afw_error.h.

◆ AFW_THROW_ERROR_FOOTPRINT_Z

#define AFW_THROW_ERROR_FOOTPRINT_Z (   code,
  message_z,
  xctx 
)
Value:
do { \
afw_error_set_z(afw_error_code_ ## code, \
footprint.source_z, message_z, xctx); \
longjmp(((xctx)->current_try->throw_jmp_buf), (afw_error_code_ ## code)); \
} while (0)

Macro used to set error and 0 rv in xctx using line number in footprint then throw it.

Parameters
codeto be appended to afw_error_code_
message_zerror message.
xctxof caller.

Always follow with a semicolon;

Definition at line 388 of file afw_error.h.

◆ AFW_THROW_ERROR_FZ

#define AFW_THROW_ERROR_FZ (   code,
  xctx,
  format_z,
  ... 
)
Value:
do { \
afw_error_set_fz(afw_error_code_ ## code, \
AFW__FILE_LINE__, xctx, format_z, __VA_ARGS__); \
longjmp(((xctx)->current_try->throw_jmp_buf), (afw_error_code_ ## code)); \
} while (0)

Macro used to set error and 0 rv in xctx and throw it.

Parameters
codeto be appended to afw_error_code_
xctxof caller.
format_zformat for error message
...for format_z

Always follow with a semicolon;

Definition at line 319 of file afw_error.h.

◆ AFW_THROW_ERROR_RV_FZ

#define AFW_THROW_ERROR_RV_FZ (   code,
  rv_source_id,
  rv,
  xctx,
  format_z,
  ... 
)
Value:
do { \
afw_error_rv_set_fz(afw_error_code_ ## code, \
AFW_ERROR_RV_SOURCE_ID_Z_ ## rv_source_id, rv, \
AFW__FILE_LINE__, xctx, format_z, __VA_ARGS__); \
longjmp(((xctx)->current_try->throw_jmp_buf), (afw_error_code_ ## code)); \
} while (0)

Macro used to set error and rv in xctx and throw it.

Parameters
codeto be appended to afw_error_code_
rv_source_idto append to AFW_ERROR_RV_SOURCE_ID_Z_
rvassociated with rv_source_id
xctxof caller.
format_zformat for error message
...for format_z

Always follow with a semicolon;

Definition at line 338 of file afw_error.h.

◆ AFW_THROW_ERROR_RV_VZ

#define AFW_THROW_ERROR_RV_VZ (   code,
  rv_source_id,
  rv,
  format_z,
  ap,
  xctx 
)
Value:
do { \
afw_error_rv_set_vz(afw_error_code_ ## code, \
AFW_ERROR_RV_SOURCE_ID_Z_ ## rv_source_id, rv, \
AFW__FILE_LINE__, format_z, ap, xctx); \
longjmp(((xctx)->current_try->throw_jmp_buf), (afw_error_code_ ## code)); \
} while (0)

Macro used to set error and rv in xctx and throw it.

Parameters
codeto be appended to afw_error_code_
rv_source_idto append to AFW_ERROR_RV_SOURCE_ID_Z_
rvassociated with rv_source_id
format_zformat for error message
aparguments for format_z
xctxof caller.

Definition at line 371 of file afw_error.h.

◆ AFW_THROW_ERROR_RV_Z

#define AFW_THROW_ERROR_RV_Z (   code,
  rv_source_id,
  rv,
  message_z,
  xctx 
)
Value:
do { \
afw_error_rv_set_z(afw_error_code_ ## code, \
AFW_ERROR_RV_SOURCE_ID_Z_ ## rv_source_id, rv, \
AFW__FILE_LINE__, message_z, xctx); \
longjmp(((xctx)->current_try->throw_jmp_buf), (afw_error_code_ ## code)); \
} while (0)

Macro used to set error and rv in xctx and throw it.

Parameters
codeto be appended to afw_error_code_
rv_source_idto append to AFW_ERROR_RV_SOURCE_ID_Z_
rvassociated with rv_source_id_z
message_zerror message.
xctxof caller.

Always follow with a semicolon;

Definition at line 301 of file afw_error.h.

◆ AFW_THROW_ERROR_VZ

#define AFW_THROW_ERROR_VZ (   code,
  format_z,
  ap,
  xctx 
)
Value:
do { \
afw_error_set_vz(afw_error_code_ ## code, \
AFW__FILE_LINE__, format_z, ap, xctx); \
longjmp(((xctx)->current_try->throw_jmp_buf), (afw_error_code_ ## code)); \
} while (0)

Macro used to set error and 0 rv in xctx and throw it.

Parameters
codeto be appended to afw_error_code_
format_zformat for error message
aparguments for format_z
xctxof caller.

Always follow with a semicolon;

Definition at line 355 of file afw_error.h.

◆ AFW_THROW_ERROR_Z

#define AFW_THROW_ERROR_Z (   code,
  message_z,
  xctx 
)
Value:
do { \
afw_error_set_z(afw_error_code_ ## code, \
AFW__FILE_LINE__, message_z, xctx); \
longjmp(((xctx)->current_try->throw_jmp_buf), (afw_error_code_ ## code)); \
} while (0)

Macro used to set error and 0 rv in xctx and throw it.

Parameters
codeto be appended to afw_error_code_
message_zerror message.
xctxof caller.

Always follow with a semicolon;

Definition at line 283 of file afw_error.h.

◆ AFW_THROW_MEMORY_ERROR

#define AFW_THROW_MEMORY_ERROR (   xctx)
Value:
do { \
afw_error_set_z(afw_error_code_memory, \
AFW__FILE_LINE__, "Memory error", xctx); \
longjmp(((xctx)->current_try->throw_jmp_buf), (afw_error_code_memory)); \
} while (0)

Macro used to set memory error in xctx and throw it.

Always follow with a semicolon;

Definition at line 499 of file afw_error.h.

◆ AFW_THROW_UNHANDLED_ERROR

#define AFW_THROW_UNHANDLED_ERROR (   unhandled_error,
  _ERROR,
  _CODE,
  _RV_SOURCE_ID,
  _RV,
  _MESSAGE_Z 
)
Value:
do { \
(_ERROR)->code = afw_error_code_ ## _CODE; \
(_ERROR)->source_z = AFW__FILE_LINE__;\
(_ERROR)->rv_source_id_z = #_RV_SOURCE_ID; \
(_ERROR)->rv = _RV; \
(_ERROR)->rv_decoded_z = NULL; \
(_ERROR)->message_z = _MESSAGE_Z; \
longjmp((unhandled_error)->throw_jmp_buf, afw_error_code_ ##_CODE); \
} while (0);

Macro used to set error and return.

This macro should normally only be used when an xctx is not available. AFW_THROW related macros should be used instead.

Definition at line 182 of file afw_error.h.

◆ AFW_TRY

#define AFW_TRY
Value:
do {\
\
afw_size_t this_TOP_OFFSET; \
afw_try_t this_TRY; \
afw_error_t this_THROWN_ERROR; \
afw_boolean_t this_ERROR_OCCURRED = false; \
afw_boolean_t this_ERROR_CAUGHT = false; \
AFW_POSSIBLY_UNUSED_VARIABLE afw_boolean_t this_FINALLY_ENTERED = false; \
this_TRY.prev = xctx->current_try;\
xctx->current_try = &this_TRY;\
this_TOP_OFFSET = xctx->evaluation_stack->top - \
xctx->evaluation_stack->first; \
do { \
if (setjmp(this_TRY.throw_jmp_buf) != 0) { \
AFW_ERROR_COPY(&this_THROWN_ERROR, xctx->error); \
AFW_ERROR_CLEAR_PARTIAL(xctx->error); \
if (this_ERROR_OCCURRED) { \
this_THROWN_ERROR.recursive_error = true; \
this_ERROR_CAUGHT = false; \
break; \
} \
this_ERROR_OCCURRED = true; \
} \
else { \
do
_Bool afw_boolean_t
Definition: afw_common.h:373

Begin an AFW TRY block.

The variable name of the current xctx must be named xctx.

AFW_ERROR_THROWN can be used to access a copy of the thrown error struct (const afw_error_t *) in AFW_CATCH and AFW_CATCH_UNHANDLED.

Variable names this_ERROR_COPIED, this_THROWN_ERROR, this_TOP_OFFSET, and this_TRY are used internal by AFW TRY block macros.

— WARNING —

DO NOT use return, goto, or any other means of exiting TRY block, TRY_CATCH* blocks or AFW_FINALLY block, other than the associated AFW_ macros or the xctx's current_try will not be set correctly and AFW_FINALLY might be skipped.

AFW_TRY and associated macros are used as follows:

AFW_TRY { (Required) Beginning of TRY block, where "xctx" is the current xctx's pointer variable.

... Body of TRY.

break; (optional) goes to AFW_FINALLY if present or ENDTRY if not.

}

AFW_CATCH(error_code) { (Optional) Zero or more AFW_CATCH macros with error_code of type afw_error_codet.

... Body of CATCH.

// AFW_ERROR_THROWN can be used to access error. // example: puts(AFW_ERROR_THROWN->message_z)

break; (optional) goes to AFW_FINALLY if present or ENDTRY if not.

AFW_MARK_UNHANDLED; (Optional) Marks error as unhandled and breaks. AFW_ENDTRY will rethrow error.

}

AFW_CATCH_UNHANDLED { (Optional) AFW_CATCH_UNHANDLED macro.

... Body of CATCH executed for errors not handled by previous AFW_CATCH().

// AFW_ERROR_THROWN can be used to access error. // example: puts(AFW_ERROR_THROWN->message_z)

break; (optional) goes to AFW_FINALLY if present or ENDTRY if not.

AFW_MARK_UNHANDLED; (Optional) Marks error as unhandled and breaks. AFW_ENDTRY will rethrow error.

}

AFW_FINALLY { (Optional) AFW_FINALLY macro.

... Body of FINALLY is executed after the body of the AFW_TRY and bodies of AFW_CATCH* macros, regardless of whether an error has occurred.

break; (optional) goes to AFW_ENDTRY

}

AFW_ENDTRY; (Required) End of TRY block. The xctx's current_try will be set to its value before entering the TRY block. If error is unhandled, it will be rethrown.

Definition at line 634 of file afw_error.h.

Typedef Documentation

◆ afw_error_footprint_t

error footprint

This is used with AFW_ERROR_FOOTPRINT and AFW_THROW_ERROR_FOOTPRINT* macros

Function Documentation

◆ afw_error_add_to_object()

void afw_error_add_to_object ( const afw_object_t object,
const afw_error_t error,
afw_xctx_t xctx 
)

Add error info to existing object using specified pool.

Parameters
objectto set error properties in.
errorinfo.
xctxof caller.

This function leaves xctx->error unchanged if it is successful.

Definition at line 862 of file afw_error.c.

◆ afw_error_allow_in_response()

afw_boolean_t afw_error_allow_in_response ( afw_error_code_t  code)

Determine if the error object for code is allowed in HTTP response.

Parameters
codeerror code.
Returns
boolean result.

Definition at line 1082 of file afw_error.c.

◆ afw_error_code_id_z()

const afw_utf8_z_t* afw_error_code_id_z ( const afw_error_t error)

Returns error->code id.

Parameters
errorstruct.
Returns
description.

Definition at line 1062 of file afw_error.c.

◆ afw_error_http_status()

afw_error_http_status ( const afw_error_t error)

Returns http status for error.

Parameters
errorstruct.
Returns
http status.

Definition at line 1041 of file afw_error.c.

◆ afw_error_message()

const afw_utf8_z_t* afw_error_message ( afw_xctx_t xctx,
const afw_utf8_z_t format,
  ... 
)

Build message in xctx error message_wa and return pointer.

Parameters
xctxof caller.
formatFormat string.
...List of arguments need by format string.
Returns
pointer to message_wa in xctx->error.

This function leaves xctx->error unchanged if it is successful.

This is for use with AFW_ERROR related macros for formatted message. Messages are built in error's message_wa which is pre-allocated.

Definition at line 1023 of file afw_error.c.

◆ afw_error_message_vz()

const afw_utf8_z_t* afw_error_message_vz ( const afw_utf8_z_t format,
va_list  ap,
afw_xctx_t xctx 
)

Build message in xctx error message_wa and return pointer.

Parameters
formatFormat string.
apArgument list initialized by va_start used by format string.
xctxof caller.
Returns
pointer to message_wa in xctx->error.

This function leaves xctx->error unchanged if it is successful.

This is for use with AFW_ERROR related macros for formatted message. Messages are built in error's message_wa which is pre-allocated.

Definition at line 1012 of file afw_error.c.

◆ afw_error_print()

int afw_error_print ( FILE *  fp,
const afw_error_t error 
)

Print error.

Parameters
fpopen FILE.
errorto print.
Returns
negative if error writing to fp.

Definition at line 679 of file afw_error.c.

◆ afw_error_print_with_xctx()

int afw_error_print_with_xctx ( FILE *  fp,
const afw_error_t error,
const afw_pool_t p,
afw_xctx_t xctx 
)

Print error when xctx is available.

Parameters
fpopen FILE.
errorto print.
pto use if needed.
xctxof caller.
Returns
negative if error writing to fp.

An evaluation backtrace will be printed if available when flag response:error:backtraceEvaluation is on.

Definition at line 783 of file afw_error.c.

◆ afw_error_to_object()

const afw_object_t* afw_error_to_object ( const afw_error_t error,
const afw_pool_t p,
afw_xctx_t xctx 
)

Create an object with error info in specified pool.

Parameters
errorinfo.
pto use for object.
xctxof caller.
Returns
object with error.

This function leaves xctx->error unchanged if it is successful.

Definition at line 998 of file afw_error.c.

◆ afw_error_to_utf8()

const afw_utf8_t* afw_error_to_utf8 ( const afw_error_t error,
const afw_pool_t p,
afw_xctx_t xctx 
)

Convert error to utf8.

Parameters
errorstruct.
pto use.
xctxof caller.
Returns
error as a string.
Todo:
FIXME: "%.0" AFW_SIZE_T_FMT should cause 0 not to be printed, but it does.

Definition at line 547 of file afw_error.c.

◆ afw_error_write_log()

void afw_error_write_log ( afw_log_priority_t  priority,
const afw_error_t error,
afw_xctx_t xctx 
)

Write error to environment log.

Parameters
prioritylevel.
errorto write.
xctxof caller.

This function leaves xctx->error unchanged if it is successful.

Todo:
FIXME:

Definition at line 639 of file afw_error.c.