105 lines
7.1 KiB
HTML
105 lines
7.1 KiB
HTML
<!-- Common Lisp HyperSpec (TM), version 7.0 generated by Kent M. Pitman on Mon, 11-Apr-2005 2:31am EDT -->
|
|
<HTML>
|
|
<HEAD>
|
|
<TITLE>CLHS: Function ERROR</TITLE>
|
|
<LINK HREF="../Data/clhs.css" REL="stylesheet" TYPE="text/css" />
|
|
<META HTTP-EQUIV="Author" CONTENT="Kent M. Pitman">
|
|
<META HTTP-EQUIV="Organization" CONTENT="LispWorks Ltd.">
|
|
<LINK REL=TOP HREF="../Front/index.htm">
|
|
<LINK REL=COPYRIGHT HREF="../Front/Help.htm#Legal">
|
|
<LINK REL=DISCLAIMER HREF="../Front/Help.htm#Disclaimer">
|
|
<LINK REL=PREV HREF="m_assert.htm">
|
|
<LINK REL=UP HREF="c_condit.htm">
|
|
<LINK REL=NEXT HREF="f_cerror.htm">
|
|
</HEAD>
|
|
<BODY>
|
|
<H1><A REV=MADE HREF="http://www.lispworks.com/"><IMG WIDTH=80 HEIGHT=65 ALT="[LISPWORKS]" SRC="../Graphics/LWSmall.gif" ALIGN=Bottom></A><A REL=TOP HREF="../Front/index.htm"><IMG WIDTH=237 HEIGHT=65 ALT="[Common Lisp HyperSpec (TM)]" SRC="../Graphics/CLHS_Sm.gif" ALIGN=Bottom></A> <A REL=PREV HREF="m_assert.htm"><IMG WIDTH=40 HEIGHT=40 ALT="[Previous]" SRC="../Graphics/Prev.gif" ALIGN=Bottom></A><A REL=UP HREF="c_condit.htm"><IMG WIDTH=40 HEIGHT=40 ALT="[Up]" SRC="../Graphics/Up.gif" ALIGN=Bottom></A><A REL=NEXT HREF="f_cerror.htm"><IMG WIDTH=40 HEIGHT=40 ALT="[Next]" SRC="../Graphics/Next.gif" ALIGN=Bottom></A></H1>
|
|
|
|
<HR>
|
|
|
|
<A NAME="error"><I>Function</I> <B>ERROR</B></A> <P>
|
|
<P><B>Syntax:</B><P>
|
|
<P>
|
|
|
|
<B>error</B> <I>datum <TT>&rest</TT> arguments</I> =>| <P>
|
|
<P>
|
|
<P><B>Arguments and Values:</B><P>
|
|
<P>
|
|
<I>datum</I>, <I>arguments</I>---<A REL=DEFINITION HREF="26_glo_d.htm#designator"><I>designators</I></A> for a <A REL=DEFINITION HREF="26_glo_c.htm#condition"><I>condition</I></A> of default type <A REL=DEFINITION HREF="e_smp_er.htm#simple-error"><B>simple-error</B></A>. <P>
|
|
<P><B>Description:</B><P>
|
|
<P>
|
|
<A REL=DEFINITION HREF="#error"><B>error</B></A> effectively invokes <A REL=DEFINITION HREF="f_signal.htm#signal"><B>signal</B></A> on the denoted <A REL=DEFINITION HREF="26_glo_c.htm#condition"><I>condition</I></A>. <P>
|
|
If the <A REL=DEFINITION HREF="26_glo_c.htm#condition"><I>condition</I></A> is not handled, <TT>(invoke-debugger </TT><I>condition</I><TT>)</TT> is done. As a consequence of calling <A REL=DEFINITION HREF="f_invoke.htm#invoke-debugger"><B>invoke-debugger</B></A>, <A REL=DEFINITION HREF="#error"><B>error</B></A> cannot directly return; the only exit from <A REL=DEFINITION HREF="#error"><B>error</B></A> can come by non-local transfer of control in a handler or by use of an interactive debugging command. <P>
|
|
<P><B>Examples:</B><P>
|
|
<P>
|
|
<PRE>
|
|
(defun factorial (x)
|
|
(cond ((or (not (typep x 'integer)) (minusp x))
|
|
(error "~S is not a valid argument to FACTORIAL." x))
|
|
((zerop x) 1)
|
|
(t (* x (factorial (- x 1))))))
|
|
=> FACTORIAL
|
|
(factorial 20)
|
|
=> 2432902008176640000
|
|
(factorial -1)
|
|
>> Error: -1 is not a valid argument to FACTORIAL.
|
|
>> To continue, type :CONTINUE followed by an option number:
|
|
>> 1: Return to Lisp Toplevel.
|
|
>> Debug>
|
|
</PRE>
|
|
</TT> <P>
|
|
<PRE>
|
|
(setq a 'fred)
|
|
=> FRED
|
|
(if (numberp a) (1+ a) (error "~S is not a number." A))
|
|
>> Error: FRED is not a number.
|
|
>> To continue, type :CONTINUE followed by an option number:
|
|
>> 1: Return to Lisp Toplevel.
|
|
>> Debug> :Continue 1
|
|
>> Return to Lisp Toplevel.
|
|
|
|
(define-condition not-a-number (error)
|
|
((argument :reader not-a-number-argument :initarg :argument))
|
|
(:report (lambda (condition stream)
|
|
(format stream "~S is not a number."
|
|
(not-a-number-argument condition)))))
|
|
=> NOT-A-NUMBER
|
|
|
|
(if (numberp a) (1+ a) (error 'not-a-number :argument a))
|
|
>> Error: FRED is not a number.
|
|
>> To continue, type :CONTINUE followed by an option number:
|
|
>> 1: Return to Lisp Toplevel.
|
|
>> Debug> :Continue 1
|
|
>> Return to Lisp Toplevel.
|
|
</PRE>
|
|
</TT> <P>
|
|
<P><B>Side Effects:</B><P>
|
|
<P>
|
|
<A REL=DEFINITION HREF="26_glo_h.htm#handler"><I>Handlers</I></A> for the specified condition, if any, are invoked and might have side effects. Program execution might stop, and the debugger might be entered. <P>
|
|
<P><B>Affected By:</B><P>
|
|
<P>
|
|
Existing handler bindings. <P>
|
|
<A REL=DEFINITION HREF="v_break_.htm#STbreak-on-signalsST"><B>*break-on-signals*</B></A> <P>
|
|
<P><B>Exceptional Situations:</B> None.
|
|
<P>
|
|
Signals an error of <A REL=DEFINITION HREF="26_glo_t.htm#type"><I>type</I></A> <A REL=DEFINITION HREF="e_tp_err.htm#type-error"><B>type-error</B></A> if <I>datum</I> and <I>arguments</I> are not <A REL=DEFINITION HREF="26_glo_d.htm#designator"><I>designators</I></A> for a <A REL=DEFINITION HREF="26_glo_c.htm#condition"><I>condition</I></A>. <P>
|
|
<P><B>See Also:</B><P>
|
|
<P>
|
|
<A REL=DEFINITION HREF="f_cerror.htm#cerror"><B>cerror</B></A>, <A REL=DEFINITION HREF="f_signal.htm#signal"><B>signal</B></A>, <A REL=DEFINITION HREF="f_format.htm#format"><B>format</B></A>, <A REL=DEFINITION HREF="m_ignore.htm#ignore-errors"><B>ignore-errors</B></A>, <A REL=DEFINITION HREF="v_break_.htm#STbreak-on-signalsST"><B>*break-on-signals*</B></A>, <A REL=DEFINITION HREF="m_handle.htm#handler-bind"><B>handler-bind</B></A>, <A REL=CHILD HREF="09_a.htm">Section 9.1 (Condition System Concepts)</A> <P>
|
|
<P><B>Notes:</B><P>
|
|
<P>
|
|
Some implementations may provide debugger commands for interactively returning from individual stack frames. However, it should be possible for the programmer to feel confident about writing code like: <P>
|
|
<PRE>
|
|
(defun wargames:no-win-scenario ()
|
|
(if (error "pushing the button would be stupid."))
|
|
(push-the-button))
|
|
</PRE>
|
|
</TT> In this scenario, there should be no chance that <A REL=DEFINITION HREF="#error"><B>error</B></A> will return and the button will get pushed. <P>
|
|
While the meaning of this program is clear and it might be proven `safe' by a formal theorem prover, such a proof is no guarantee that the program is safe to execute. Compilers have been known to have bugs, computers to have signal glitches, and human beings to manually intervene in ways that are not always possible to predict. Those kinds of errors, while beyond the scope of the condition system to formally model, are not beyond the scope of things that should seriously be considered when writing code that could have the kinds of sweeping effects hinted at by this example. <P>
|
|
<HR>
|
|
|
|
<A REL=NAVIGATOR HREF="../Front/StartPts.htm"><IMG WIDTH=80 HEIGHT=40 ALT="[Starting Points]" SRC="../Graphics/StartPts.gif" ALIGN=Bottom></A><A REL=TOC HREF="../Front/Contents.htm"><IMG WIDTH=80 HEIGHT=40 ALT="[Contents]" SRC="../Graphics/Contents.gif" ALIGN=Bottom></A><A REL=INDEX HREF="../Front/X_Master.htm"><IMG WIDTH=80 HEIGHT=40 ALT="[Index]" SRC="../Graphics/Index.gif" ALIGN=Bottom></A><A REL=INDEX HREF="../Front/X_Symbol.htm"><IMG WIDTH=80 HEIGHT=40 ALT="[Symbols]" SRC="../Graphics/Symbols.gif" ALIGN=Bottom></A><A REL=GLOSSARY HREF="../Body/26_a.htm"><IMG WIDTH=80 HEIGHT=40 ALT="[Glossary]" SRC="../Graphics/Glossary.gif" ALIGN=Bottom></A><A HREF="../Front/X3J13Iss.htm"><IMG WIDTH=80 HEIGHT=40 ALT="[Issues]" SRC="../Graphics/Issues.gif" ALIGN=Bottom></A><BR>
|
|
|
|
<A REL=COPYRIGHT HREF="../Front/Help.htm#Legal"><I>Copyright 1996-2005, LispWorks Ltd. All rights reserved.</I></A><P>
|
|
</BODY>
|
|
</HTML>
|