Allow for multiple exception handling in catch statements

Description

Java already supports multiple exception handling. ColdFusion does not and it introduces tons of verbosity which could be avoided if catch could allow for multiple exceptions. Introduce the pipe parameter to define multi-catch exception blocks.

Activity

Luis Majano 
6 December 2021 at 15:57

Wow that’s amazing ! Anything we can do to help?

Also, I have placed the same ticket on the Adobe tracker so hopefully, compatibility can remain. It would an incredible departure of precedent if Adobe decides to use another demarcation symbol, but anything is possible

David Rogers 
5 December 2021 at 15:46

I have a working prototype of this up at .

It updates only the script parser/codegen, it does not touch the tag parser / codegen…would this feature touch tags?

The following test passes:

And some parsing/transformation errors for:

catch (a | b) {} // must provide a name if catching more than one exception

catch (a | | b) {} // expected a typename after "|"

I do share Adam’s concern over adding language features that Adobe might either never implement, or implement differently, introducing an unresolvable incompatibility.

Luis Majano 
1 December 2021 at 17:43

FYI, Groovy uses the same syntax as well, more precedent: http://groovy-lang.org/semantics.html#_multi_catch

Adam Cameron 
1 December 2021 at 17:38

I puzzled over that too. It’s mirroring Java’s syntax which is legit, and in the case of Java, | is apparently a union operator (and is used only in this situation).

I read this here:

The choice of | for this is likely because it's the standard syntax for a union type in other languages. The language spec even calls it a "union", though it's only syntactically valid in this construct (as of Java 7): "An exception parameter may denote its type as either a single class type or a union of two or more class types (called alternatives). The alternatives of a union are syntactically separated by |."

I think that’s legit reasoning.

It’s interesting that elsewhere in Java that | is the “bitwise or” operator, so it’s quite odd to have the same symbol used in two different ways. But… I’m sure they thought about this.

Zac Spitzer 
1 December 2021 at 16:51

any reason not to just use || instead of | ?

Details

Assignee

Reporter

New Issue warning screen

Before you create a new Issue, please post to the mailing list first https://dev.lucee.org

Once the issue has been verified, one of the Lucee team will ask you to file an issue

Priority

Created 30 November 2021 at 22:07
Updated 6 December 2021 at 15:57