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
12extern "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
41{
43 jmp_buf context;
47
50
51/* Add an exception in the stack */
52void push_exception(void);
53/* Pop an exceptions from the stack */
54void 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 */
jmp_buf context
saving the current context
Definition: n_exceptions.h:43
struct ExceptionContextList * head
pointer to the next stacked exception
Definition: n_exceptions.h:45
void pop_exception(int)
Function to pop an exception in the list.
Definition: n_exceptions.c:42
ExceptionContextList * __Exceptions
Globale variable for exception stack management.
Definition: n_exceptions.c:14
void push_exception(void)
Function to push an exception in the list.
Definition: n_exceptions.c:21
Exception stack structure.
Definition: n_exceptions.h:41