[r6rs-discuss] Re: [email@example.com: Re: [Formal] Recursive
exception handling considered harmful]
schlie at comcast.net
Sun Mar 18 12:50:15 EDT 2007
In regard to what Taylor R Campbell wrote:
Largely agree, however personally I prefer:
- The ability of functions to define named exception handlers via:
(catch (<exception/handler-name> <params>) <hander-code>), which will
be implicitly invoked upon an exception of that name being generated
within or propagated into its scope of its definition or subsequent
- The ability of functions to emit named exceptions within its scope
via: (throw (<exception/handler-name> <params>)).
Thereby hypothetically more simply:
(define (/ x y)
(if (= y 0) ; detect div-by-zero exception,
(throw (</:except> x y)) ; return thrown result, if any;
<compute-division>)) ; or otherwise computed value.
(define (some-function a b c)
(catch (</:except> n d) ; define local / handler
(if (and (= n 0) (= d 0)) 0 ; if 0/0 then return 0,
(throw (</:except> n d)))) ; else propagate exception.
(+ a (/ b c) (/ a c))) ; thereby local uses of (/ 0 0) return 0.
And thereby as previously suggested, a default handler may be defined and
which may be optionally overridden for the top-level scope which will catch
all otherwise uncaught exceptions, display errors and terminate evaluation,
or return a default value depending on the nature of the exception.
Where as in effect the exception behavior defined by a catch hander
becomes the default exception behavior for all such exceptions evaluated
within its scope until otherwise overridden within a hierarchically deeper
evaluation context; any function which relies on a particular default
exception behavior must define that catch behavior locally, or utilize
locally defined functions which have correspondingly defined their catch
behaviors to the default behaviors, or hypothetically call such sensitive
functions with explicit catch-handlers hypothetically via:
(try-with-catch (<some-function> ...)
(<exception/handler-name> <default-exception/handler-name>) ...)
Thereby default-catch-handlers may be specified for a particular call
which override any which may have been otherwise specified at outer
levels of evaluation hierarchy.
Thereby avoiding the explicit use of continuations, as just a thought.
More information about the r6rs-discuss