3 * Handles odd errors in Steel programs
5 * 1.00 (24 September 1993)
7 * © 1993-1998 Straylight
10 /*----- Licensing note ----------------------------------------------------*
12 * This file is part of Straylight's Steel library.
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)
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.
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.
33 #include "exception.h"
44 static BOOL exception__handled;
45 static int *exception__handler;
48 * int exception_registerHandler(exception_handler env)
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 exception_handlers in a
54 * function and then return.
57 * exception_handler env == an undefined variable of the type
61 #ifndef exception_registerHandler
62 #define exception_registerHandler(env) \
63 (exception__registerHandler((env),setjmp(env)))
67 * void exception_generate(char *message,...)
70 * Generates a Steel exception, to be handled in an appropriate manner.
73 * char *message == printf()-type format string
76 void exception_generate(char *message,...)
81 vsprintf(buffer,message,ap);
83 visdelay_suspend(); /* It doesn't mind if we suspend indefinitely */
84 if (exception__handled==FALSE)
86 werr(FALSE,msgs_lookup("excFATAL:Fatal internal error: '%s'"),buffer);
91 if (werr_error((wimpt_options() & wimpt_ONOBACKTRACE) ? 2 : 3,
92 msgs_lookup("excSEV:Internal error: '%s'. Click OK "
93 "to continue, or Cancel to quit %s."),
95 wimpt_programname())==0)
98 msgs_lookup("excAYS:Are you sure you want to quit %s? "
99 "Click OK to continue, or Cancel to quit."),
100 wimpt_programname())==0)
105 longjmp(exception__handler,1);
108 longjmp(exception__handler,1);
113 * int exception__registerHandler(jmp_buf handler)
116 * This routine is for the use of exception segment only, and should not be
117 * called from your code.
120 int exception__registerHandler(jmp_buf handler,int result)
124 exception__handled=TRUE;
125 exception__handler=handler;