81 lines
5.8 KiB
HTML
81 lines
5.8 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: Variable *DEBUGGER-HOOK*</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="f_break.htm">
|
|
<LINK REL=UP HREF="c_condit.htm">
|
|
<LINK REL=NEXT HREF="v_break_.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="f_break.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="v_break_.htm"><IMG WIDTH=40 HEIGHT=40 ALT="[Next]" SRC="../Graphics/Next.gif" ALIGN=Bottom></A></H1>
|
|
|
|
<HR>
|
|
|
|
<A NAME="STdebugger-hookST"><I>Variable</I> <B>*DEBUGGER-HOOK*</B></A> <P>
|
|
<P><B>Value Type:</B><P>
|
|
<P>
|
|
a <A REL=DEFINITION HREF="26_glo_d.htm#designator"><I>designator</I></A> for a <A REL=DEFINITION HREF="26_glo_f.htm#function"><I>function</I></A> of two <A REL=DEFINITION HREF="26_glo_a.htm#argument"><I>arguments</I></A> (a <A REL=DEFINITION HREF="26_glo_c.htm#condition"><I>condition</I></A> and the <A REL=DEFINITION HREF="26_glo_v.htm#value"><I>value</I></A> of <A REL=DEFINITION HREF="#STdebugger-hookST"><B>*debugger-hook*</B></A> at the time the debugger was entered), or <A REL=DEFINITION HREF="a_nil.htm#nil"><B>nil</B></A>. <P>
|
|
<P><B>Initial Value:</B><P>
|
|
<P>
|
|
<A REL=DEFINITION HREF="a_nil.htm#nil"><B>nil</B></A>. <P>
|
|
<P><B>Description:</B><P>
|
|
<P>
|
|
When the <A REL=DEFINITION HREF="26_glo_v.htm#value"><I>value</I></A> of <A REL=DEFINITION HREF="#STdebugger-hookST"><B>*debugger-hook*</B></A> is <A REL=DEFINITION HREF="26_glo_n.htm#non-nil"><I>non-nil</I></A>, it is called prior to normal entry into the debugger, either due to a call to <A REL=DEFINITION HREF="f_invoke.htm#invoke-debugger"><B>invoke-debugger</B></A> or due to automatic entry into the debugger from a call to <A REL=DEFINITION HREF="f_error.htm#error"><B>error</B></A> or <A REL=DEFINITION HREF="f_cerror.htm#cerror"><B>cerror</B></A> with a condition that is not handled. The <A REL=DEFINITION HREF="26_glo_f.htm#function"><I>function</I></A> may either handle the <A REL=DEFINITION HREF="26_glo_c.htm#condition"><I>condition</I></A> (transfer control) or return normally (allowing the standard debugger to run). To minimize recursive errors while debugging, <A REL=DEFINITION HREF="#STdebugger-hookST"><B>*debugger-hook*</B></A> is bound to <A REL=DEFINITION HREF="a_nil.htm#nil"><B>nil</B></A> by <A REL=DEFINITION HREF="f_invoke.htm#invoke-debugger"><B>invoke-debugger</B></A> prior to calling the <A REL=DEFINITION HREF="26_glo_f.htm#function"><I>function</I></A>. <P>
|
|
<P><B>Examples:</B><P>
|
|
<P>
|
|
<PRE>
|
|
(defun one-of (choices &optional (prompt "Choice"))
|
|
(let ((n (length choices)) (i))
|
|
(do ((c choices (cdr c)) (i 1 (+ i 1)))
|
|
((null c))
|
|
(format t "~&[~D] ~A~%" i (car c)))
|
|
(do () ((typep i `(integer 1 ,n)))
|
|
(format t "~&~A: " prompt)
|
|
(setq i (read))
|
|
(fresh-line))
|
|
(nth (- i 1) choices)))
|
|
|
|
(defun my-debugger (condition me-or-my-encapsulation)
|
|
(format t "~&Fooey: ~A" condition)
|
|
(let ((restart (one-of (compute-restarts))))
|
|
(if (not restart) (error "My debugger got an error."))
|
|
(let ((*debugger-hook* me-or-my-encapsulation))
|
|
(invoke-restart-interactively restart))))
|
|
|
|
(let ((*debugger-hook* #'my-debugger))
|
|
(+ 3 'a))
|
|
>> Fooey: The argument to +, A, is not a number.
|
|
>> [1] Supply a replacement for A.
|
|
>> [2] Return to Cloe Toplevel.
|
|
>> Choice: 1
|
|
>> Form to evaluate and use: (+ 5 'b)
|
|
>> Fooey: The argument to +, B, is not a number.
|
|
>> [1] Supply a replacement for B.
|
|
>> [2] Supply a replacement for A.
|
|
>> [3] Return to Cloe Toplevel.
|
|
>> Choice: 1
|
|
>> Form to evaluate and use: 1
|
|
=> 9
|
|
</PRE>
|
|
</TT> <P>
|
|
<P><B>Affected By:</B><P>
|
|
<P>
|
|
<A REL=DEFINITION HREF="f_invoke.htm#invoke-debugger"><B>invoke-debugger</B></A> <P>
|
|
<P><B>See Also:</B> None.
|
|
<P>
|
|
<P><B>Notes:</B><P>
|
|
<P>
|
|
When evaluating code typed in by the user interactively, it is sometimes useful to have the hook function bind <A REL=DEFINITION HREF="#STdebugger-hookST"><B>*debugger-hook*</B></A> to the <A REL=DEFINITION HREF="26_glo_f.htm#function"><I>function</I></A> that was its second argument so that recursive errors can be handled using the same interactive facility. <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>
|