Nilorea Library
C utilities for networking, threading, graphics
Loading...
Searching...
No Matches
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#endif
14
20#include <stdio.h>
21#include <stdlib.h>
22#include <setjmp.h>
23
25#define NO_EXCEPTION 0
27#define ARRAY_EXCEPTION 2
29#define DIVZERO_EXCEPTION 4
31#define OVERFLOW_EXCEPTION 8
33#define PARSING_EXCEPTION 16
34
36#define GENERAL_EXCEPTION ARRAY_EXCEPTION | DIVZERO_EXCEPTION | OVERFLOW_EXCEPTION | PARSING_EXCEPTION
37
45
48
49/* Add an exception in the stack */
50void push_exception(void);
51/* Pop an exceptions from the stack */
52void pop_exception(int);
53
55#define Try \
56 { \
57 int __exc_; \
58 push_exception(); \
59 __exc_ = setjmp(__Exceptions->context); \
60 if (__exc_ == NO_EXCEPTION) {
62#define Catch(X) \
63 } \
64 if (__exc_ & (X)) { \
65 __exc_ = 0;
66
68#define CatchAll() \
69 } \
70 if (__exc_ != 0) { \
71 __exc_ = 0;
72
74#define EndTry \
75 } \
76 pop_exception(__exc_); \
77 }
78
80#define Throw(X) \
81 n_log(LOG_ERR, "Exception thrown type:%d", X); \
82 longjmp(__Exceptions->context, (X))
83
88#ifdef __cplusplus
89}
90#endif
91
92#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.