Initial revision
[ssr] / StraySrc / Libraries / Steel / h / exception
1 /*
2 * Exception
3 * Handles odd errors in Steel programs
4 *
5 * 1.00 (24 September 1991)
6 *
7 * © 1991-1998 Straylight
8 */
9
10 /*----- Licensing note ----------------------------------------------------*
11 *
12 * This file is part of Straylight's Steel library.
13 *
14 * Steel is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 2, or (at your option)
17 * any later version.
18 *
19 * Steel is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 *
24 * You should have received a copy of the GNU General Public License
25 * along with Steel. If not, write to the Free Software Foundation,
26 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
27 */
28
29 #ifndef __exception_h
30 #define __exception_h
31
32 #ifndef __setjmp_h
33 #include <setjmp.h>
34 #endif
35
36 #ifndef __dll_h
37 #include "dll.h"
38 #endif
39
40 typedef struct
41 {
42 jmp_buf j;
43 int sp;
44 }
45 exception_handler;
46
47 /*
48 * int exception_registerHandler(exception_handler env)
49 *
50 * Use
51 * Registers the current point as being a sensible place to go after an
52 * exception. This is implemented as a macro for the simple reason that
53 * things tend to go a tad wrong if you define your jmp_bufs in a function
54 * and then return.
55 *
56 * Parameters
57 * exception_handler env == an undefined variable of the type jmp_buf.
58 */
59
60 #ifndef exception_registerHandler
61 #define exception_registerHandler(exc) \
62 ( \
63 ( exc.sp=_dll_setjmp() ), \
64 ( exception__registerHandler((exc.j),setjmp(exc.j)) ? \
65 (_dll_longjmped(exc.sp),1) : \
66 0) \
67 )
68 #endif
69
70
71 /*
72 * void exception_generate(char *message,...)
73 *
74 * Use
75 * Generates an ArmenLib exception, to be handled in an appropriate manner.
76 *
77 * Parameters
78 * char *message == printf()-type format string
79 */
80
81 void exception_generate(char *message,...);
82
83
84 /*
85 * int exception__registerHandler(jmp_buf handler)
86 *
87 * Use
88 * This routine is for the use of exception segment only, and should not
89 * be called from your code.
90 */
91
92 int exception__registerHandler(jmp_buf handler,int result);
93
94 #endif