Nilorea Library
C utilities for networking, threading, graphics
Loading...
Searching...
No Matches
n_exceptions.h
Go to the documentation of this file.
1
8
#ifndef ____EXCEPTION___MANAGEMENT__FOR_C
9
#define ____EXCEPTION___MANAGEMENT__FOR_C
10
11
#ifdef __cplusplus
12
extern
"C"
{
13
#endif
14
20
#include <stdio.h>
21
#include <stdlib.h>
22
#include <setjmp.h>
23
25
#define NO_EXCEPTION 0
27
#define ARRAY_EXCEPTION 2
29
#define DIVZERO_EXCEPTION 4
31
#define OVERFLOW_EXCEPTION 8
33
#define PARSING_EXCEPTION 16
34
36
#define GENERAL_EXCEPTION ARRAY_EXCEPTION | DIVZERO_EXCEPTION | OVERFLOW_EXCEPTION | PARSING_EXCEPTION
37
39
typedef
struct
ExceptionContextList
{
41
jmp_buf
context
;
43
struct
ExceptionContextList
*
head
;
44
}
ExceptionContextList
;
45
47
extern
ExceptionContextList
*
__Exceptions
;
48
49
/* Add an exception in the stack */
50
void
push_exception
(
void
);
51
/* Pop an exceptions from the stack */
52
void
pop_exception
(
int
);
53
55
#define Try \
56
{ \
57
int __exc_; \
58
push_exception(); \
59
__exc_ = setjmp(__Exceptions->context); \
60
if (__exc_ == NO_EXCEPTION) {
62
#define Catch(X) \
63
} \
64
if (__exc_ & (X)) { \
65
__exc_ = 0;
66
68
#define CatchAll() \
69
} \
70
if (__exc_ != 0) { \
71
__exc_ = 0;
72
74
#define EndTry \
75
} \
76
pop_exception(__exc_); \
77
}
78
80
#define Throw(X) \
81
n_log(LOG_ERR, "Exception thrown type:%d", X); \
82
longjmp(__Exceptions->context, (X))
83
88
#ifdef __cplusplus
89
}
90
#endif
91
92
#endif
/* #ifndef ____EXCEPTION___MANAGEMENT__FOR_C */
ExceptionContextList::context
jmp_buf context
saving the current context
Definition
n_exceptions.h:41
ExceptionContextList::head
struct ExceptionContextList * head
pointer to the next stacked exception
Definition
n_exceptions.h:43
pop_exception
void pop_exception(int)
Function to pop an exception in the list.
Definition
n_exceptions.c:33
__Exceptions
ExceptionContextList * __Exceptions
Globale variable for exception stack management.
Definition
n_exceptions.c:13
push_exception
void push_exception(void)
Function to push an exception in the list.
Definition
n_exceptions.c:18
ExceptionContextList
Exception stack structure.
Definition
n_exceptions.h:39
include
nilorea
n_exceptions.h
Generated on Mon Jun 9 2025 22:06:43 for Nilorea Library by
1.9.8