1b2699de46c381de29b5aaf56a785b34277de5cf
1 /* Copyright (C) 1995,1996,1997 Free Software Foundation, Inc.
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2, or (at your option)
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this software; see the file COPYING. If not, write to
15 * the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
16 * Boston, MA 02111-1307 USA
18 * As a special exception, the Free Software Foundation gives permission
19 * for additional uses of the text contained in its release of GUILE.
21 * The exception is that, if you link the GUILE library with other files
22 * to produce an executable, this does not by itself cause the
23 * resulting executable to be covered by the GNU General Public License.
24 * Your use of that executable is in no way restricted on account of
25 * linking the GUILE library code into it.
27 * This exception does not however invalidate any other reasons why
28 * the executable file might be covered by the GNU General Public License.
30 * This exception applies only to the code released by the
31 * Free Software Foundation under the name GUILE. If you copy
32 * code from other Free Software Foundation releases into a copy of
33 * GUILE, as the General Public License permits, the exception does
34 * not apply to the code that you add in this way. To avoid misleading
35 * anyone as to the status of such modified files, you must delete
36 * this exception notice from them.
38 * If you write modifications of your own for GUILE, it is your choice
39 * whether to permit this exception to apply to your modifications.
40 * If you do not wish that, delete this exception notice. */
57 /* {Errors and Exceptional Conditions}
63 void (*scm_error_callback
) () = 0;
65 /* All errors should pass through here. */
67 scm_error (key
, subr
, message
, args
, rest
)
75 if (scm_error_callback
)
76 (*scm_error_callback
) (key
, subr
, message
, args
, rest
);
78 arg_list
= scm_listify (subr
? scm_makfrom0str (subr
) : SCM_BOOL_F
,
79 message
? scm_makfrom0str (message
) : SCM_BOOL_F
,
83 scm_ithrow (key
, arg_list
, 1);
85 /* No return, but just in case: */
87 write (2, "unhandled system error\n",
88 sizeof ("unhandled system error\n") - 1);
92 /* Scheme interface to scm_error. */
93 SCM_PROC(s_error_scm
, "scm-error", 5, 0, 0, scm_error_scm
);
95 scm_error_scm (key
, subr
, message
, args
, rest
)
102 SCM_ASSERT (SCM_NIMP (key
) && SCM_SYMBOLP (key
), key
, SCM_ARG1
, s_error_scm
);
103 SCM_ASSERT (SCM_FALSEP (subr
) || (SCM_NIMP (subr
) && SCM_ROSTRINGP (subr
)),
104 subr
, SCM_ARG2
, s_error_scm
);
105 SCM_ASSERT (SCM_FALSEP (message
)
106 || (SCM_NIMP (message
) && SCM_ROSTRINGP (message
)),
107 message
, SCM_ARG3
, s_error_scm
);
109 SCM_COERCE_SUBSTR (message
);
112 (SCM_FALSEP (subr
)) ? NULL
: SCM_ROCHARS (subr
),
113 (SCM_FALSEP (message
)) ? NULL
: SCM_ROCHARS (message
),
119 SCM_SYMBOL (scm_system_error_key
, "system-error");
124 scm_error (scm_system_error_key
,
127 scm_listify (scm_makfrom0str (strerror (errno
)),
129 scm_listify (SCM_MAKINUM (errno
), SCM_UNDEFINED
));
133 scm_syserror_msg (subr
, message
, args
, eno
)
139 scm_error (scm_system_error_key
,
143 scm_listify (SCM_MAKINUM (eno
), SCM_UNDEFINED
));
147 scm_sysmissing (subr
)
151 scm_error (scm_system_error_key
,
154 scm_listify (scm_makfrom0str (strerror (ENOSYS
)), SCM_UNDEFINED
),
155 scm_listify (SCM_MAKINUM (ENOSYS
), SCM_UNDEFINED
));
157 scm_error (scm_system_error_key
,
161 scm_listify (SCM_MAKINUM (0), SCM_UNDEFINED
));
165 SCM_SYMBOL (scm_num_overflow_key
, "numerical-overflow");
167 scm_num_overflow (subr
)
170 scm_error (scm_num_overflow_key
,
172 "Numerical overflow",
177 SCM_SYMBOL (scm_out_of_range_key
, "out-of-range");
179 scm_out_of_range (subr
, bad_value
)
183 scm_error (scm_out_of_range_key
,
185 "Argument out of range: %S",
186 scm_listify (bad_value
, SCM_UNDEFINED
),
190 SCM_SYMBOL (scm_args_number_key
, "wrong-number-of-args");
192 scm_wrong_num_args (proc
)
195 scm_error (scm_args_number_key
,
197 "Wrong number of arguments to %s",
198 scm_listify (proc
, SCM_UNDEFINED
),
202 SCM_SYMBOL (scm_arg_type_key
, "wrong-type-arg");
204 scm_wrong_type_arg (subr
, pos
, bad_value
)
209 scm_error (scm_arg_type_key
,
211 (pos
== 0) ? "Wrong type argument: %S"
212 : "Wrong type argument in position %s: %S",
213 (pos
== 0) ? scm_listify (bad_value
, SCM_UNDEFINED
)
214 : scm_listify (SCM_MAKINUM (pos
), bad_value
, SCM_UNDEFINED
),
218 SCM_SYMBOL (scm_memory_alloc_key
, "memory-allocation-error");
220 scm_memory_error (subr
)
223 scm_error (scm_memory_alloc_key
,
225 "Memory allocation error",
230 SCM_SYMBOL (scm_misc_error_key
, "misc-error");
232 scm_misc_error (subr
, message
, args
)
237 scm_error (scm_misc_error_key
, subr
, message
, args
, SCM_BOOL_F
);
240 /* implements the SCM_ASSERT interface. */
242 scm_wta (arg
, pos
, s_subr
)
247 if (!s_subr
|| !*s_subr
)
249 if ((~0x1fL
) & (long) pos
)
251 /* error string supplied. */
252 scm_misc_error (s_subr
, pos
, SCM_EOL
);
256 /* numerical error code. */
257 int error
= (long) pos
;
262 scm_wrong_type_arg (s_subr
, 0, arg
);
264 scm_wrong_type_arg (s_subr
, 1, arg
);
266 scm_wrong_type_arg (s_subr
, 2, arg
);
268 scm_wrong_type_arg (s_subr
, 3, arg
);
270 scm_wrong_type_arg (s_subr
, 4, arg
);
272 scm_wrong_type_arg (s_subr
, 5, arg
);
274 scm_wrong_num_args (arg
);
276 scm_out_of_range (s_subr
, arg
);
278 scm_memory_error (s_subr
);
280 /* this shouldn't happen. */
281 scm_misc_error (s_subr
, "Unknown error", SCM_EOL
);
284 return SCM_UNSPECIFIED
;
287 /* obsolete interface: scm_everr (exp, env, arg, pos, s_subr)
288 was equivalent to scm_wta (arg, pos, s_subr) */
293 #include "cpp_err_symbols.c"