Nilorea Library
C utilities for networking, threading, graphics
Loading...
Searching...
No Matches
n_exceptions.h
Go to the documentation of this file.
1
9
#ifndef ____EXCEPTION___MANAGEMENT__FOR_C
10
#define ____EXCEPTION___MANAGEMENT__FOR_C
11
12
#ifdef __cplusplus
13
extern
"C"
{
14
#endif
15
21
#include <stdio.h>
22
#include <stdlib.h>
23
#include <setjmp.h>
24
26
#define NO_EXCEPTION 0
28
#define ARRAY_EXCEPTION 2
30
#define DIVZERO_EXCEPTION 4
32
#define OVERFLOW_EXCEPTION 8
34
#define PARSING_EXCEPTION 16
35
37
#define GENERAL_EXCEPTION ARRAY_EXCEPTION | DIVZERO_EXCEPTION | OVERFLOW_EXCEPTION | PARSING_EXCEPTION
38
40
typedef
struct
ExceptionContextList
{
42
jmp_buf
context
;
44
struct
ExceptionContextList
*
head
;
45
}
ExceptionContextList
;
46
48
extern
ExceptionContextList
*
__Exceptions
;
49
50
/* Add an exception in the stack */
51
void
push_exception
(
void
);
52
/* Pop an exceptions from the stack */
53
void
pop_exception
(
int
);
54
56
#define Try \
57
{ \
58
volatile int __exc_; \
59
push_exception(); \
60
__exc_ = setjmp(__Exceptions->context); \
61
if (__exc_ == NO_EXCEPTION) {
63
#define Catch(X) \
64
} \
65
if (__exc_ & (X)) { \
66
__exc_ = 0;
67
69
#define CatchAll() \
70
} \
71
if (__exc_ != 0) { \
72
__exc_ = 0;
73
75
#define EndTry \
76
} \
77
pop_exception(__exc_); \
78
}
79
81
#define Throw(X) \
82
n_log(LOG_ERR, "Exception thrown type:%d", X); \
83
longjmp(__Exceptions->context, (X))
84
89
#ifdef __cplusplus
90
}
91
#endif
92
93
#endif
/* #ifndef ____EXCEPTION___MANAGEMENT__FOR_C */
ExceptionContextList::context
jmp_buf context
saving the current context
Definition
n_exceptions.h:42
ExceptionContextList::head
struct ExceptionContextList * head
pointer to the next stacked exception
Definition
n_exceptions.h:44
pop_exception
void pop_exception(int)
Function to pop an exception in the list.
Definition
n_exceptions.c:34
__Exceptions
ExceptionContextList * __Exceptions
Globale variable for exception stack management.
Definition
n_exceptions.c:14
push_exception
void push_exception(void)
Function to push an exception in the list.
Definition
n_exceptions.c:19
ExceptionContextList
Exception stack structure.
Definition
n_exceptions.h:40
include
nilorea
n_exceptions.h
Generated on Wed Jul 16 2025 22:55:56 for Nilorea Library by
1.9.8