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, 675 Mass Ave, Cambridge, MA 02139, USA.
17 * As a special exception, the Free Software Foundation gives permission
18 * for additional uses of the text contained in its release of GUILE.
20 * The exception is that, if you link the GUILE library with other files
21 * to produce an executable, this does not by itself cause the
22 * resulting executable to be covered by the GNU General Public License.
23 * Your use of that executable is in no way restricted on account of
24 * linking the GUILE library code into it.
26 * This exception does not however invalidate any other reasons why
27 * the executable file might be covered by the GNU General Public License.
29 * This exception applies only to the code released by the
30 * Free Software Foundation under the name GUILE. If you copy
31 * code from other Free Software Foundation releases into a copy of
32 * GUILE, as the General Public License permits, the exception does
33 * not apply to the code that you add in this way. To avoid misleading
34 * anyone as to the status of such modified files, you must delete
35 * this exception notice from them.
37 * If you write modifications of your own for GUILE, it is your choice
38 * whether to permit this exception to apply to your modifications.
39 * If you do not wish that, delete this exception notice.
57 /* {Errors and Exceptional Conditions}
61 /* True between SCM_DEFER_INTS and SCM_ALLOW_INTS, and
62 * when the interpreter is not running at all.
64 int scm_ints_disabled
= 1;
68 static void err_head
SCM_P ((char *str
));
75 if (SCM_NIMP (scm_cur_outp
))
76 scm_fflush (scm_cur_outp
);
77 scm_gen_putc ('\n', scm_cur_errp
);
79 if (SCM_BOOL_F
!= *scm_loc_loadpath
)
81 scm_prin1 (*scm_loc_loadpath
, scm_cur_errp
, 1);
82 scm_gen_puts (scm_regular_string
, ", line ", scm_cur_errp
);
83 scm_intprint ((long) scm_linum
, 10, scm_cur_errp
);
84 scm_gen_puts (scm_regular_string
, ": ", scm_cur_errp
);
87 scm_fflush (scm_cur_errp
);
89 if (scm_cur_errp
== scm_def_errp
)
99 SCM_PROC(s_errno
, "errno", 0, 1, 0, scm_errno
);
105 if (!SCM_UNBNDP (arg
))
107 if (SCM_FALSEP (arg
))
110 errno
= SCM_INUM (arg
);
112 return SCM_MAKINUM (old
);
115 SCM_PROC(s_perror
, "perror", 1, 0, 0, scm_perror
);
120 SCM_ASSERT (SCM_NIMP (arg
) && SCM_STRINGP (arg
), arg
, SCM_ARG1
, s_perror
);
121 err_head (SCM_CHARS (arg
));
122 return SCM_UNSPECIFIED
;
125 void (*scm_error_callback
) () = 0;
127 /* all errors thrown from C should pass through here. */
129 scm_error (key
, subr
, message
, args
, rest
)
137 if (scm_error_callback
)
138 (*scm_error_callback
) (key
, subr
, message
, args
, rest
);
140 arg_list
= scm_listify (subr
? scm_makfrom0str (subr
) : SCM_BOOL_F
,
141 message
? scm_makfrom0str (message
) : SCM_BOOL_F
,
145 scm_ithrow (key
, arg_list
, 1);
147 /* No return, but just in case: */
149 write (2, "unhandled system error", sizeof ("unhandled system error") - 1);
153 SCM_SYMBOL (scm_system_error_key
, "system-error");
158 scm_error (scm_system_error_key
,
161 scm_listify (scm_makfrom0str (strerror (errno
)),
163 scm_listify (SCM_MAKINUM (errno
), SCM_UNDEFINED
));
167 scm_syserror_msg (subr
, message
, args
, eno
)
173 scm_error (scm_system_error_key
,
177 scm_listify (SCM_MAKINUM (eno
), SCM_UNDEFINED
));
181 scm_sysmissing (subr
)
185 scm_error (scm_system_error_key
,
188 scm_listify (scm_makfrom0str (strerror (ENOSYS
)), SCM_UNDEFINED
),
189 scm_listify (SCM_MAKINUM (ENOSYS
), SCM_UNDEFINED
));
191 scm_error (scm_system_error_key
,
195 scm_listify (SCM_MAKINUM (0), SCM_UNDEFINED
));
199 SCM_SYMBOL (scm_num_overflow_key
, "numerical-overflow");
201 scm_num_overflow (subr
)
204 scm_error (scm_num_overflow_key
,
206 "Numerical overflow",
211 SCM_SYMBOL (scm_out_of_range_key
, "out-of-range");
213 scm_out_of_range (subr
, bad_value
)
217 scm_error (scm_out_of_range_key
,
219 "Argument out of range: %S",
220 scm_listify (bad_value
, SCM_UNDEFINED
),
224 SCM_SYMBOL (scm_args_number_key
, "wrong-number-of-args");
226 scm_wrong_num_args (proc
)
229 scm_error (scm_args_number_key
,
231 "Wrong number of arguments to %s",
232 scm_listify (proc
, SCM_UNDEFINED
),
236 SCM_SYMBOL (scm_arg_type_key
, "wrong-type-arg");
238 scm_wrong_type_arg (subr
, pos
, bad_value
)
243 scm_error (scm_arg_type_key
,
245 (pos
== 0) ? "Wrong type argument: %S"
246 : "Wrong type argument in position %s: %S",
247 (pos
== 0) ? scm_listify (bad_value
, SCM_UNDEFINED
)
248 : scm_listify (SCM_MAKINUM (pos
), bad_value
, SCM_UNDEFINED
),
252 SCM_SYMBOL (scm_memory_alloc_key
, "memory-allocation-error");
254 scm_memory_error (subr
)
257 scm_error (scm_memory_alloc_key
,
259 "Memory allocation error",
264 SCM_SYMBOL (scm_misc_error_key
, "misc-error");
266 scm_misc_error (subr
, message
, args
)
271 scm_error (scm_misc_error_key
, subr
, message
, args
, SCM_BOOL_F
);
274 /* implements the SCM_ASSERT interface. */
276 scm_wta (arg
, pos
, s_subr
)
281 if (!s_subr
|| !*s_subr
)
283 if ((~0x1fL
) & (long) pos
)
285 /* error string supplied. */
286 scm_misc_error (s_subr
, pos
, SCM_BOOL_F
);
290 /* numerical error code. */
291 int error
= (long) pos
;
296 scm_wrong_type_arg (s_subr
, 0, arg
);
298 scm_wrong_type_arg (s_subr
, 1, arg
);
300 scm_wrong_type_arg (s_subr
, 2, arg
);
302 scm_wrong_type_arg (s_subr
, 3, arg
);
304 scm_wrong_type_arg (s_subr
, 4, arg
);
306 scm_wrong_type_arg (s_subr
, 5, arg
);
308 scm_wrong_num_args (arg
);
310 scm_out_of_range (s_subr
, arg
);
312 scm_memory_error (s_subr
);
314 /* this shouldn't happen. */
315 scm_misc_error (s_subr
, "Unknown error", SCM_BOOL_F
);
318 return SCM_UNSPECIFIED
;
321 /* obsolete interface: scm_everr (exp, env, arg, pos, s_subr)
322 was equivalent to scm_wta (arg, pos, s_subr) */