Nilorea Library

- Main Page
- Modules
- Data Structures
- Files

- File List
- Globals

All Data Structures Files Functions Variables Typedefs Macros Groups
test_exceptions.c
Go to the documentation of this file.
1 #include <stdio.h>
2 #include <memory.h>
3
4
5
6 #include "n_exceptions.h"
7
8
9
10 int array_exception( int boolean )
11 {
12 if( boolean )
13 {
14 printf( "Throwed signal\n" );
15 Throw( ARRAY_EXCEPTION );
16 }
17 printf( "No signal Throwed !\n");
18
19 return 1 ;
20 }
21
22 int divzero_exception( int boolean )
23 {
24 if( boolean )
25 {
26 printf( "Throwed signal\n" );
27 Throw( DIVZERO_EXCEPTION );
28 }
29 printf( "No signal Throwed !\n");
30
31 return 1 ;
32 }
33
34 int overflow_exception( int boolean )
35 {
36 if( boolean )
37 {
38 printf( "Throwed signal\n" );
39 Throw( OVERFLOW_EXCEPTION );
40 }
41 printf( "No signal Throwed !\n");
42
43 return 1 ;
44 }
45
46 int parsing_exception( int boolean )
47 {
48 if( boolean )
49 {
50 printf( "Throwed signal\n" );
51 Throw( PARSING_EXCEPTION );
52 }
53 printf( "No signal Throwed !\n");
54
55 return 1 ;
56 }
57
58 int all_exception( int boolean )
59 {
60 if( boolean )
61 {
62 printf( "Throwed signal\n" );
63 Throw( PARSING_EXCEPTION );
64 }
65 printf( "No signal Throwed !\n");
66
67 return 1 ;
68 }
69
70
71 int main( int argc, char *argv[] )
72 {
73 allegro_init();
74 /***************************************************************/
75 puts( "ArrayNoCatch" );
76 Try
77 {
78 printf( "Trying signal:ARRAY_EXCEPTION false\n" );
79 array_exception( 0 );
80 printf( "Trying signal:ARRAY_EXCEPTION true\n" );
81 array_exception( 1 );
82 }
83 EndTry ;
84 puts( "ArrayCatch" );
85 Try
86 {
87 printf( "Trying signal:ARRAY_EXCEPTION false\n" );
88 array_exception( 0 );
89 printf( "Trying signal:ARRAY_EXCEPTION true\n" );
90 array_exception( 1 );
91 }
92 Catch( ARRAY_EXCEPTION )
93 {
94 printf( "Caught signal ARRAY_EXCEPTION\n" );
95 }
96 EndTry ;
97 /***************************************************************/
98 puts( "DivZeroNoCatch" );
99 Try
100 {
101 printf( "Trying signal:DIVZERO_EXCEPTION false\n" );
102 divzero_exception( 0 );
103 printf( "Trying signal:DIVZERO_EXCEPTION true\n" );
104 divzero_exception( 1 );
105 }
106 EndTry ;
107 puts( "DivZeroCatch" );
108 Try
109 {
110 printf( "Trying signal:DIVZERO_EXCEPTION false\n" );
111 divzero_exception( 0 );
112 printf( "Trying signal:DIVZERO_EXCEPTION true\n" );
113 divzero_exception( 1 );
114 }
115 Catch( DIVZERO_EXCEPTION )
116 {
117 printf( "Caught signal DIVZERO_EXCEPTION\n" );
118 }
119 EndTry ;
120 /***************************************************************/
121 Try
122 {
123 printf( "Trying signal:OVERFLOW_EXCEPTION false\n" );
124 overflow_exception( 0 );
125 printf( "Trying signal:OVERFLOW_EXCEPTION true\n" );
126 overflow_exception( 1 );
127 }
128 EndTry ;
129 Try
130 {
131 printf( "Trying signal:OVERFLOW_EXCEPTION false\n" );
132 overflow_exception( 0 );
133 printf( "Trying signal:OVERFLOW_EXCEPTION true\n" );
134 overflow_exception( 1 );
135 }
136 Catch( OVERFLOW_EXCEPTION )
137 {
138 printf( "Caught signal OVERFLOW_EXCEPTION \n" );
139 }
140 EndTry ;
141 /***************************************************************/
142 Try
143 {
144 printf( "Trying signal:PARSING_EXCEPTION false\n" );
145 parsing_exception( 0 );
146 printf( "Trying signal:PARSING_EXCEPTION true\n" );
147 parsing_exception( 1 );
148 }
149 EndTry ;
150 Try
151 {
152 printf( "Trying signal:PARSING_EXCEPTION false\n" );
153 parsing_exception( 0 );
154 printf( "Trying signal:PARSING_EXCEPTION true\n" );
155 parsing_exception( 1 );
156 }
157 Catch( PARSING_EXCEPTION )
158 {
159 printf( "Caught signal PARSING_EXCEPTION\n" );
160 }
161 EndTry ;
162 /***************************************************************/
163 Try
164 {
165 printf( "Trying signal:ALL_EXCEPTION false\n" );
166 all_exception( 0 );
167 printf( "Trying signal:ALL_EXCEPTION true\n" );
168 all_exception( 1 );
169 }
170 EndTry ;
171 Try
172 {
173 printf( "Trying signal:ALL_EXCEPTION false\n" );
174 all_exception( 0 );
175 printf( "Trying signal:ALL_EXCEPTION true\n" );
176 all_exception( 1 );
177 }
178 Catch( GENERAL_EXCEPTION )
179 {
180 printf( "Caught signal matching GENERAL_EXCEPTION\n" );
181 }
182 EndTry ;
183
184
185 Try
186 {
187 printf( "Trying mixed Try-Catch blocks, we are inside block 1\n" );
188 Try
189 {
190 printf( "We're inside block 2\n" );
191 Throw( ARRAY_EXCEPTION );
192
193 }
194 Catch( GENERAL_EXCEPTION )
195 {
196 printf( "Catched inside block 2\n" );
197 }
198 EndTry ;
199 Throw( OVERFLOW_EXCEPTION );
200 }
201 Catch( GENERAL_EXCEPTION )
202 {
203 printf( "Catched inside block 1\n" );
204
205 }
206 EndTry ;
207
208 return 1 ;
209
210 }END_OF_MAIN()
211
212