Should masked exceptions be an error?

Nick Sabalausky a at a.a
Tue Nov 24 13:42:48 PST 2009


"Brad Roberts" <braddr at bellevue.puremagic.com> wrote in message 
news:alpine.DEB.2.00.0911241319190.18188 at bellevue.puremagic.com...
> On Mon, 23 Nov 2009, Andrei Alexandrescu wrote:
>
>> Consider:
>>
>> try {
>>    ...
>> } catch (Exception) {
>>    ...
>> } catch (StdioException) {
>>    ...
>> }
>>
>> The second handler never matches because StdioException is a subclass of
>> Exception, so the first handler will always match whatever the second 
>> matches.
>>
>> Should that be a compile-time error? I think so.
>>
>>
>> Andrei
>
> Alternate thought.. should order matter or should it automatically sort
> such that most specific catch is preferred.  Sort of matches the
> declaration order doesn't (ok, shouldn't) matter philosophy.

Use first match:
+ Consistent with "else if"

Use most specific match:
+ Consistent with template pattern matching
+ Possibly more practical
- I can just imagine all the bugs this would probably have in DMD

Personally, I'm torn. I'd probably lean more towards "most specific match", 
but I'd be perfectly happy either way.





More information about the Digitalmars-d mailing list