From: Gabriel D. R. <gd...@in...> - 2011-06-20 17:26:17
|
Hi, Evaluation of the form (/ 1 0) drops into the debugger with the message debugger invoked on a DIVISION-BY-ZERO in thread #<THREAD "initial thread" RUNNING {1002950EA1}>: arithmetic error DIVISION-BY-ZERO signalled Operation was SB-KERNEL::DIVISION, operands (1 0). Yet, that condition (DIVISION-BY-ZERO) seems to escape handlers. E.g. the following form drops into the debugger instead of producing 0. (handler-bind ((division-by-zero #'(lambda (c) 0))) (/ 1 0)) -- Gaby |
From: Zach B. <xa...@xa...> - 2011-06-20 17:31:40
|
Gabriel Dos Reis <gd...@in...> writes: > Yet, that condition (DIVISION-BY-ZERO) seems to escape handlers. > E.g. the following form drops into the debugger instead of producing 0. > > (handler-bind ((division-by-zero #'(lambda (c) 0))) (/ 1 0)) Your handler does not handle the condition; it does not perform a non-local transfer of control. Try adding a catch/throw or block/return-from or similar. Zach |
From: Gabriel D. R. <gd...@in...> - 2011-06-20 17:38:29
|
On Mon, Jun 20, 2011 at 12:31 PM, Zach Beane <xa...@xa...> wrote: > Gabriel Dos Reis <gd...@in...> writes: > >> Yet, that condition (DIVISION-BY-ZERO) seems to escape handlers. >> E.g. the following form drops into the debugger instead of producing 0. >> >> (handler-bind ((division-by-zero #'(lambda (c) 0))) (/ 1 0)) > > Your handler does not handle the condition; it does not perform a > non-local transfer of control. Try adding a catch/throw or > block/return-from or similar. Oops, you're right. Sorry for the false alarm. -- Gaby |
From: Anton K. <an...@sw...> - 2011-06-20 17:43:45
|
Gabriel Dos Reis <gd...@in...> writes: > Yet, that condition (DIVISION-BY-ZERO) seems to escape handlers. > E.g. the following form drops into the debugger instead of producing 0. > > (handler-bind ((division-by-zero #'(lambda (c) 0))) (/ 1 0)) > Handler specified for handler-bind is supposed to exit non-locally, otherwise it "declines" to handle condition, and other/outer handlers are invoked. Handler-case does what you're evidently looking for: (handler-case (/ 1 0) (division-by-zero () 0)) ;; cases, not lambdas The same with handler-bind and non-local exit: (block nil (handler-bind ((division-by-zero #'(lambda () (return 0)))) (/ 1 0))) -- Regards, Anton Kovalenko +7(916)345-34-02 | Elektrostal' MO, Russia |
From: Gabriel D. R. <gd...@in...> - 2011-06-20 18:08:08
|
On Mon, Jun 20, 2011 at 12:43 PM, Anton Kovalenko <an...@sw...> wrote: > Handler-case does what you're evidently looking for: Yes, I realized my mistake upon reading Zach's message. Thanks to both of you. -- Gaby |
From: Gabriel D. R. <gd...@in...> - 2011-06-20 19:53:28
|
On Mon, Jun 20, 2011 at 12:43 PM, Anton Kovalenko <an...@sw...> wrote: > (handler-case (/ 1 0) > (division-by-zero () 0)) ;; cases, not lambdas SBCL signals DIVISION-BY-ZERO on (LOG 0). That gives the expectation that one could extract the operands of the division. However, the following form (handler-case (log 0) (division-by-zero (c) (arithmetic-error-operands c))) drops into the debugger claiming unbound condition slot: SB-KERNEL::OPERANDS -- Gaby |