Should masked exceptions be an error?

Steven Schveighoffer schveiguy at yahoo.com
Tue Nov 24 13:36:27 PST 2009


On Tue, 24 Nov 2009 16:20:14 -0500, Brad Roberts  
<braddr at bellevue.puremagic.com> wrote:

> 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.

If this is possible, it makes the most sense to me.  I don't see how it's  
not possible, since inheritance trees cannot have cycles, and therefore  
should always be sortable.

-Steve



More information about the Digitalmars-d mailing list