Nilorea Library

- Main Page
- Modules
- Data Structures
- Files

- File List
- Globals

All Data Structures Files Functions Variables Typedefs Macros Groups
n_exceptions.c
Go to the documentation of this file.
1
9 #include "n_exceptions.h"
10
11
12 ExceptionContextList* __Exceptions = NULL;
13
14
18 void push_exception()
19 {
20 ExceptionContextList *_new = ( ExceptionContextList * )malloc( sizeof( ExceptionContextList ) );
21
22 if( _new )
23 {
24 _new->head = __Exceptions;
25 __Exceptions = _new;
26 }
27 else
28 {
29 n_log( LOG_ERR , "Cannot even add a new exception context !!" );
30 exit( FALSE );
31 }
32 } /* push_exception() */
33
34
35
40 void pop_exception( int ex )
41 {
42 int no_known_exception = 1 ;
43 ExceptionContextList *head = NULL ;
44 head = __Exceptions -> head;
45 Free( __Exceptions );
46 __Exceptions = head;
47
48 if( ex != NO_EXCEPTION )
49 {
50 if( __Exceptions )
51 {
52 longjmp( __Exceptions -> context , ex );
53 }
54 else
55 {
56 char str[256];
57 if( ex & ARRAY_EXCEPTION )
58 {
59 no_known_exception = 0 ;
60 strcpy( str, "Array exception " );
61 }
62 if( ex & DIVZERO_EXCEPTION )
63 {
64 no_known_exception = 0 ;
65 strcpy( str, "Div zero exception " );
66 }
67 if( ex & OVERFLOW_EXCEPTION )
68 {
69 no_known_exception = 0 ;
70 strcpy( str, "Overflow exception " );
71 }
72 if( ex & PARSING_EXCEPTION )
73 {
74 no_known_exception = 0 ;
75 strcpy( str , "Parsing exception " );
76 }
77 if( no_known_exception )
78 {
79 strcpy( str , "Unknow exception" );
80 n_log( LOG_ERR , "Exception number: %d, message: %s" , ex , str );
81 exit(-1);
82 }
83 n_log( LOG_ERR , "Exception number: %d, message: %s" , ex , str );
84 }
85 }
86 } /* pop_exception */
87