35#include "ws_symbol_export.h"
36#include "ws_attributes.h"
38#define XCEPT_GROUP_ANY 0
39#define XCEPT_CODE_ANY 0
40#define XCEPT_BAD_ALLOC 1
161WS_DLL_PUBLIC WS_NORETURN
void except_throw(
long group,
long code,
const char *msg);
171WS_DLL_PUBLIC WS_NORETURN
void except_throwd(
long group,
long code,
const char *msg,
void *data);
181WS_DLL_PUBLIC WS_NORETURN
void except_vthrowf(
long group,
long code,
const char *fmt, va_list vl);
190WS_DLL_PUBLIC WS_NORETURN
void except_throwf(
long group,
long code,
const char *fmt, ...)
205extern
unsigned long except_code(
except_t *ex);
212extern
unsigned long except_group(
except_t *ex);
219extern const
char *except_message(
except_t *ex);
226extern
void *except_data(
except_t *ex);
280#define except_code(E) ((E)->except_id.except_code)
281#define except_group(E) ((E)->except_id.except_group)
282#define except_message(E) ((E)->except_message)
283#define except_data(E) ((E)->except_dyndata)
297#define except_cleanup_push(F, C) \
299 struct except_stacknode except_sn; \
300 struct except_cleanup except_cl; \
301 except_setup_clean(&except_sn, &except_cl, F, C)
303#define except_cleanup_pop(E) \
306 except_cl.except_func(except_cl.except_context); \
309#define except_checked_cleanup_pop(F, E) \
311 assert (except_cl.except_func == (F)); \
313 except_cl.except_func(except_cl.except_context); \
318#define except_cleanup_push_pfx(pfx, F, C) \
320 struct except_stacknode pfx##_except_sn; \
321 struct except_cleanup pfx##_except_cl; \
322 except_setup_clean(&pfx##_except_sn, &pfx##_except_cl, F, C)
324#define except_cleanup_pop_pfx(pfx, E) \
327 pfx##_except_cl.except_func(pfx##_except_cl.except_context);\
330#define except_checked_cleanup_pop_pfx(pfx, F, E) \
332 assert (pfx##_except_cl.except_func == (F)); \
334 pfx##_except_cl.except_func(pfx##_except_cl.except_context);\
339#define except_try_push(ID, NUM, PPE) \
341 struct except_stacknode except_sn; \
342 struct except_catch except_ch; \
343 except_setup_try(&except_sn, &except_ch, ID, NUM); \
344 if (setjmp(except_ch.except_jmp)) \
345 *(PPE) = &except_ch.except_obj; \
349#define except_try_pop() \
350 except_free(except_ch.except_obj.except_dyndata); \
WS_DLL_PUBLIC struct except_stacknode * except_pop(void)
Pop the top node from the exception stack.
Definition except.c:270
WS_DLL_PUBLIC void except_setup_try(struct except_stacknode *, struct except_catch *, const except_id_t[], size_t)
Set up a try block for exception handling.
Definition except.c:259
WS_DLL_PUBLIC void * except_take_data(except_t *ex)
Take data from an exception object.
Definition except.c:374
const struct except_stacknode * except_get_top(void)
Get the top node from the exception stack.
Definition except.c:175
WS_DLL_PUBLIC WS_NORETURN void except_vthrowf(long group, long code, const char *fmt, va_list vl)
Throw an exception with a formatted message.
Definition except.c:323
WS_DLL_PUBLIC void except_setup_clean(struct except_stacknode *, struct except_cleanup *, void(*)(void *), void *)
Set up a cleanup handler for exception handling.
Definition except.c:249
WS_DLL_PUBLIC WS_NORETURN void except_throw(long group, long code, const char *msg)
Throw an exception with a message and optional data.
Definition except.c:288
WS_DLL_PUBLIC void(*)(except_t *) except_unhandled_catcher(void(*new_catcher)(except_t *))
Sets the unhandled exception catcher.
Definition except.h:198
WS_DLL_PUBLIC int except_init(void)
Initialize the exception handling system.
Definition except.c:160
WS_DLL_PUBLIC void except_deinit(void)
Deinitialize the exception handling system.
Definition except.c:167
WS_DLL_PUBLIC WS_NORETURN void except_throwd(long group, long code, const char *msg, void *data)
Throw an exception with a detailed message and data.
Definition except.c:306
WS_DLL_PUBLIC WS_NORETURN void except_rethrow(except_t *except)
Rethrow an exception.
Definition except.c:278
@ except_no_call
Definition except.h:47
@ except_call
Definition except.h:48
WS_DLL_PUBLIC void except_set_allocator(void *(*alloc)(size_t), void(*dealloc)(void *))
Sets custom memory allocation and deallocation functions for exception handling.
Definition except.c:381
WS_DLL_PUBLIC void * except_alloc(size_t size)
Allocates memory for an exception object.
Definition except.c:387
WS_DLL_PUBLIC WS_NORETURN void except_throwf(long group, long code, const char *fmt,...)
Throws an exception with a formatted message.
Definition except.c:332
WS_DLL_PUBLIC void except_free(void *ptr)
Frees memory allocated for an exception node.
Definition except.c:396
void except_set_top(struct except_stacknode *node)
Set the top node of an exception stack.
Definition except.c:180
except_stacktype
Discriminator tag for entries on the exception handler stack.
Definition except.h:94
@ XCEPT_CATCHER
Definition except.h:96
@ XCEPT_CLEANUP
Definition except.h:95
A catch block descriptor associating a set of exception IDs with a longjmp target.
Definition except.h:83
except_t except_obj
Definition except.h:86
const except_id_t * except_id
Definition except.h:84
size_t except_size
Definition except.h:85
jmp_buf except_jmp
Definition except.h:87
A cleanup handler registered to run when a scope is exited due to an exception.
Definition except.h:74
void * except_context
Definition except.h:76
void(* except_func)(void *)
Definition except.h:75
Identifies an exception class by group and code.
Definition except.h:55
unsigned long except_group
Definition except.h:56
unsigned long except_code
Definition except.h:57
Represents a node in the exception handling stack.
Definition except.h:106
struct except_cleanup * except_cleanup
Definition except.h:111
enum except_stacktype except_type
Definition except.h:108
struct except_stacknode * except_down
Definition except.h:107
struct except_catch * except_catcher
Definition except.h:110
Represents a thrown exception instance, including its identity, message, and dynamic data.
Definition except.h:64
except_id_t volatile except_id
Definition except.h:65
const char *volatile except_message
Definition except.h:66
void *volatile except_dyndata
Definition except.h:67