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
13extern "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
46
49
50/* Add an exception in the stack */
51void push_exception(void);
52/* Pop an exceptions from the stack */
53void 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 */
jmp_buf context
saving the current context
struct ExceptionContextList * head
pointer to the next stacked exception
void pop_exception(int)
Function to pop an exception in the list.
ExceptionContextList * __Exceptions
Globale variable for exception stack management.
void push_exception(void)
Function to push an exception in the list.
Exception stack structure.