diff options
| author | Richard M. Stallman | 2007-07-14 18:34:22 +0000 |
|---|---|---|
| committer | Richard M. Stallman | 2007-07-14 18:34:22 +0000 |
| commit | be44b862badaad8cc0a498c0f5dc9cce2a352e61 (patch) | |
| tree | 0d5347a7feec0961a700dea935c6ad9c17aa1b6a | |
| parent | 8d3719940eb01f6a63cfe2b6e05bb97b85627e3a (diff) | |
| download | emacs-be44b862badaad8cc0a498c0f5dc9cce2a352e61.tar.gz emacs-be44b862badaad8cc0a498c0f5dc9cce2a352e61.zip | |
(Handling Errors): Document `debug' in handler list.
| -rw-r--r-- | lispref/ChangeLog | 4 | ||||
| -rw-r--r-- | lispref/control.texi | 49 |
2 files changed, 38 insertions, 15 deletions
diff --git a/lispref/ChangeLog b/lispref/ChangeLog index 61bc10c1afc..6a824f8deaf 100644 --- a/lispref/ChangeLog +++ b/lispref/ChangeLog | |||
| @@ -1,3 +1,7 @@ | |||
| 1 | 2007-07-14 Richard Stallman <rms@gnu.org> | ||
| 2 | |||
| 3 | * control.texi (Handling Errors): Document `debug' in handler list. | ||
| 4 | |||
| 1 | 2007-07-09 Richard Stallman <rms@gnu.org> | 5 | 2007-07-09 Richard Stallman <rms@gnu.org> |
| 2 | 6 | ||
| 3 | * files.texi (Magic File Names): Rewrite previous change. | 7 | * files.texi (Magic File Names): Rewrite previous change. |
diff --git a/lispref/control.texi b/lispref/control.texi index 4c469a10368..e99a6329f3e 100644 --- a/lispref/control.texi +++ b/lispref/control.texi | |||
| @@ -893,6 +893,12 @@ establishing an error handler, with the special form | |||
| 893 | This deletes the file named @var{filename}, catching any error and | 893 | This deletes the file named @var{filename}, catching any error and |
| 894 | returning @code{nil} if an error occurs. | 894 | returning @code{nil} if an error occurs. |
| 895 | 895 | ||
| 896 | The @code{condition-case} construct is often used to trap errors that | ||
| 897 | are predictable, such as failure to open a file in a call to | ||
| 898 | @code{insert-file-contents}. It is also used to trap errors that are | ||
| 899 | totally unpredictable, such as when the program evaluates an expression | ||
| 900 | read from the user. | ||
| 901 | |||
| 896 | The second argument of @code{condition-case} is called the | 902 | The second argument of @code{condition-case} is called the |
| 897 | @dfn{protected form}. (In the example above, the protected form is a | 903 | @dfn{protected form}. (In the example above, the protected form is a |
| 898 | call to @code{delete-file}.) The error handlers go into effect when | 904 | call to @code{delete-file}.) The error handlers go into effect when |
| @@ -920,15 +926,33 @@ the two gets to handle it. | |||
| 920 | If an error is handled by some @code{condition-case} form, this | 926 | If an error is handled by some @code{condition-case} form, this |
| 921 | ordinarily prevents the debugger from being run, even if | 927 | ordinarily prevents the debugger from being run, even if |
| 922 | @code{debug-on-error} says this error should invoke the debugger. | 928 | @code{debug-on-error} says this error should invoke the debugger. |
| 923 | @xref{Error Debugging}. If you want to be able to debug errors that are | ||
| 924 | caught by a @code{condition-case}, set the variable | ||
| 925 | @code{debug-on-signal} to a non-@code{nil} value. | ||
| 926 | 929 | ||
| 927 | When an error is handled, control returns to the handler. Before this | 930 | If you want to be able to debug errors that are caught by a |
| 928 | happens, Emacs unbinds all variable bindings made by binding constructs | 931 | @code{condition-case}, set the variable @code{debug-on-signal} to a |
| 929 | that are being exited and executes the cleanups of all | 932 | non-@code{nil} value. You can also specify that a particular handler |
| 930 | @code{unwind-protect} forms that are exited. Once control arrives at | 933 | should let the debugger run first, by writing @code{debug} among the |
| 931 | the handler, the body of the handler is executed. | 934 | conditions, like this: |
| 935 | |||
| 936 | @example | ||
| 937 | @group | ||
| 938 | (condition-case nil | ||
| 939 | (delete-file filename) | ||
| 940 | ((debug error) nil)) | ||
| 941 | @end group | ||
| 942 | @end example | ||
| 943 | |||
| 944 | @noindent | ||
| 945 | The effect of @code{debug} here is only to prevent | ||
| 946 | @code{condition-case} from suppressing the call to the debugger. Any | ||
| 947 | given error will invoke the debugger only if @code{debug-on-error} and | ||
| 948 | the other usual filtering mechanisms say it should. @xref{Error Debugging}. | ||
| 949 | |||
| 950 | Once Emacs decides that a certain handler handles the error, it | ||
| 951 | returns control to that handler. To do so, Emacs unbinds all variable | ||
| 952 | bindings made by binding constructs that are being exited, and | ||
| 953 | executes the cleanups of all @code{unwind-protect} forms that are | ||
| 954 | being exited. Once control arrives at the handler, the body of the | ||
| 955 | handler executes normally. | ||
| 932 | 956 | ||
| 933 | After execution of the handler body, execution returns from the | 957 | After execution of the handler body, execution returns from the |
| 934 | @code{condition-case} form. Because the protected form is exited | 958 | @code{condition-case} form. Because the protected form is exited |
| @@ -937,12 +961,6 @@ execution at the point of the error, nor can it examine variable | |||
| 937 | bindings that were made within the protected form. All it can do is | 961 | bindings that were made within the protected form. All it can do is |
| 938 | clean up and proceed. | 962 | clean up and proceed. |
| 939 | 963 | ||
| 940 | The @code{condition-case} construct is often used to trap errors that | ||
| 941 | are predictable, such as failure to open a file in a call to | ||
| 942 | @code{insert-file-contents}. It is also used to trap errors that are | ||
| 943 | totally unpredictable, such as when the program evaluates an expression | ||
| 944 | read from the user. | ||
| 945 | |||
| 946 | Error signaling and handling have some resemblance to @code{throw} and | 964 | Error signaling and handling have some resemblance to @code{throw} and |
| 947 | @code{catch} (@pxref{Catch and Throw}), but they are entirely separate | 965 | @code{catch} (@pxref{Catch and Throw}), but they are entirely separate |
| 948 | facilities. An error cannot be caught by a @code{catch}, and a | 966 | facilities. An error cannot be caught by a @code{catch}, and a |
| @@ -960,7 +978,8 @@ error occurs during @var{protected-form}. | |||
| 960 | 978 | ||
| 961 | Each of the @var{handlers} is a list of the form @code{(@var{conditions} | 979 | Each of the @var{handlers} is a list of the form @code{(@var{conditions} |
| 962 | @var{body}@dots{})}. Here @var{conditions} is an error condition name | 980 | @var{body}@dots{})}. Here @var{conditions} is an error condition name |
| 963 | to be handled, or a list of condition names; @var{body} is one or more | 981 | to be handled, or a list of condition names (which can include @code{debug} |
| 982 | to allow the debugger to run before the handler); @var{body} is one or more | ||
| 964 | Lisp expressions to be executed when this handler handles an error. | 983 | Lisp expressions to be executed when this handler handles an error. |
| 965 | Here are examples of handlers: | 984 | Here are examples of handlers: |
| 966 | 985 | ||