Nilorea Library
C utilities for networking, threading, graphics
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
{
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
41
{
43
jmp_buf
context
;
45
struct
ExceptionContextList
*
head
;
46
}
ExceptionContextList
;
47
49
extern
ExceptionContextList
*
__Exceptions
;
50
51
/* Add an exception in the stack */
52
void
push_exception
(
void
);
53
/* Pop an exceptions from the stack */
54
void
pop_exception
(
int
);
55
57
#define Try \
58
{ \
59
int __exc_ ; \
60
push_exception(); \
61
__exc_ = setjmp( __Exceptions -> context ); \
62
if( __exc_ == NO_EXCEPTION ) \
63
{
64
65
67
#define Catch(X) \
68
} \
69
if( __exc_ & (X) ) \
70
{ \
71
__exc_ = 0 ;
72
74
#define CatchAll() \
75
} \
76
if( __exc_ !=0 ) \
77
{ \
78
__exc_ = 0 ;
79
80
81
83
#define EndTry \
84
} \
85
pop_exception( __exc_ ); \
86
}
87
89
#define Throw(X) \
90
n_log( LOG_ERR , "Exception thrown type:%d"
, X ); \
91
longjmp( __Exceptions -> context , (X) )
92
97
#ifdef __cplusplus
98
}
99
#endif
100
101
102
#endif
/* #ifndef ____EXCEPTION___MANAGEMENT__FOR_C */
ExceptionContextList::context
jmp_buf context
saving the current context
Definition:
n_exceptions.h:43
ExceptionContextList::head
struct ExceptionContextList * head
pointer to the next stacked exception
Definition:
n_exceptions.h:45
pop_exception
void pop_exception(int)
Function to pop an exception in the list.
Definition:
n_exceptions.c:42
__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:21
ExceptionContextList
Exception stack structure.
Definition:
n_exceptions.h:41
include
nilorea
n_exceptions.h
Generated on Thu Dec 14 2023 17:37:42 for Nilorea Library by
1.9.4