[e-lang] Bug (0.8.26h): multiple-pattern catch expansion is incorrect

Kevin Reid kpreid at attglobal.net
Thu Apr 29 17:23:31 EDT 2004


? try { throw("oops") } catch ==1 {}
# problem: oops

? try { throw("oops") } catch ==1 {} catch ==2 {}
# problem: no match: problem: oops

The expansion for multiple-catch-clause try-catch does not follow the 
semantics of the kernel try-catch when the pattern match fails - it 
creates a new exception instead of simply passing on/rethrowing the 
unmatched one.

This will be important once E has a useful exception type system (which 
I am working on a proposal for).

(A similar problem exists with matchers in object definitions, with the 
additional complication that even in Kernel-E, 
matcher-with-failing-pattern is not the same as no-matcher. This is why 
help(require) doesn't work.)

? e`try {} catch a {} catch b {}`
# value: e`try {
#            null
#        } catch specimen_1 {
#            if (specimen_1 =~ a) {
#                null
#            } else {
#                if (specimen_1 =~ b) {
#                    null
#                } else {
#                    throw.run("no match: ".add(specimen_1))
#                }
#            }
#        }`

Possible solutions:

1. Replace e`throw("no match: " + @x)` with e`throw($x)`, though there 
will still be an extra throw() in the stack trace.

2. Allow an arbitrary number of catch clauses in Kernel-E.

3. Somehow make match failure of all of the individual patterns in the 
expansion cause failure of the try-catch expression's pattern.

4. Expand each catch clause into a nested try-catch.

-- 
Kevin Reid



More information about the e-lang mailing list