November 24, 2009 Re: Should masked exceptions be an error? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Walter Bright | Walter Bright wrote:
> Andrei Alexandrescu wrote:
>> Should that be a compile-time error? I think so.
>
> =================================
> class A : Exception
> {
> this(string msg) { super(msg); }
> }
>
> void foo()
> {
> try { }
> catch (Exception e) { }
> catch (A e) { }
> }
> =================================
>
> gives:
>
> test.d(9): Error: catch at test.d(10) hides catch at test.d(11)
Great! Sorry, I don't have access to dmd.
Andrei.
|
November 24, 2009 Re: Should masked exceptions be an error? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrei Alexandrescu | 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.
|
November 24, 2009 Re: Should masked exceptions be an error? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Brad Roberts | On Tue, 24 Nov 2009 16:20:14 -0500, Brad Roberts <braddr@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 |
November 24, 2009 Re: Should masked exceptions be an error? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Brad Roberts | "Brad Roberts" <braddr@bellevue.puremagic.com> wrote in message news:alpine.DEB.2.00.0911241319190.18188@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. |
November 24, 2009 Re: Should masked exceptions be an error? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Nick Sabalausky | Nick Sabalausky wrote:
> "Brad Roberts" <braddr@bellevue.puremagic.com> wrote in message news:alpine.DEB.2.00.0911241319190.18188@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"
+ needs no work
:o)
Andrei
|
November 24, 2009 Re: Should masked exceptions be an error? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Brad Roberts | Brad Roberts wrote:
> 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.
I think the user should know if one inherits from the other, so I'm reluctant to try and hide it by sorting.
|
Copyright © 1999-2021 by the D Language Foundation