Nilorea Library

- Main Page
- Modules
- Data Structures
- Files

- File List
- Globals

All Data Structures Files Functions Variables Typedefs Macros Groups
n_exceptions.h
Go to the documentation of this file.
1
7 #ifndef ____EXCEPTION___MANAGEMENT__FOR_C
8 #define ____EXCEPTION___MANAGEMENT__FOR_C
9
10 #ifdef __cplusplus
11 extern "C"
12 {
13 #endif
14
20 #include <stdio.h>
21 #include <stdlib.h>
22 #include <setjmp.h>
23 #include "n_log.h"
24
26 #define NO_EXCEPTION 0
27
28 #define ARRAY_EXCEPTION 2
29
30 #define DIVZERO_EXCEPTION 4
31
32 #define OVERFLOW_EXCEPTION 8
33
34 #define PARSING_EXCEPTION 16
35
36 #define GENERAL_EXCEPTION ARRAY_EXCEPTION|DIVZERO_EXCEPTION|OVERFLOW_EXCEPTION|PARSING_EXCEPTION
37
39 typedef struct ExceptionContextList
40 {
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 int __exc_ ; \
59 push_exception(); \
60 __exc_ = setjmp( __Exceptions -> context ); \
61 if( __exc_ == NO_EXCEPTION ) \
62 {
63
64 #define Catch(X) \
65 } \
66 if( __exc_ & (X) ) \
67 { \
68 __exc_ = 0 ;
69
71 #define EndTry \
72 } \
73 pop_exception( __exc_ );\
74 }
75
77 #define Throw(X) \
78 longjmp( __Exceptions -> context , (X) )
79
82 #ifdef __cplusplus
83 }
84 #endif
85
86
87 #endif /* #ifndef ____EXCEPTION___MANAGEMENT__FOR_C */