Ticket #300 (new enhancement)
allow to chain a few exceptions with a single body
Reported by: | kobi7 | Owned by: | |
---|---|---|---|
Priority: | minor | Milestone: | |
Component: | Cobra Compiler | Version: | 0.8.0 |
Keywords: | Cc: |
Description
<kobi7> can I chain a few exceptions with a single body?
<kobi7> catch SysException? | XException | YException
<kobi7> body of catch statement, that fits all of them
<CobraCommander> nope they have to be separate catches
<kobi7> in that case, the body is duplicated
<CobraCommander> you could break it out to a separate method
<CobraCommander> also in the case of "catch x as SysException? | XException | YException" there is the question of what type to give to "x"
<kobi7> ofcourse. I saw that syntax in a java proposal, maybe it got to java7. thought it's a nice addition
<kobi7> http://docs.oracle.com/javase/7/docs/technotes/guides/language/catch-multiple.html
...
<CobraCommander> so i presume you can use methods on "ex" that the two types have in common, but they don't spell that out and they don't show an example
<CobraCommander> also since .net doesn't have this feature, we'd have to map it. presumably by generating each "catch" block on behalf of the programmer
<CobraCommander> I guess the type of "ex" could be the greatest common denominator of all the types
<CobraCommander> the Cobra compiler already has code to compute such a thing because it is used in other places, like inferring the inner type of a list literal
<CobraCommander> if you don't want me to lose track of this idea, fill out a ticket at the cobra web site. :-)