Jump to page: 1 2
Thread overview
Should masked exceptions be an error?
Nov 24, 2009
Denis Koroskin
Nov 24, 2009
Ary Borenszweig
Nov 24, 2009
Michal Minich
Nov 24, 2009
Ary Borenszweig
Nov 24, 2009
Nick Sabalausky
Nov 24, 2009
Denis Koroskin
Nov 24, 2009
Walter Bright
Nov 24, 2009
Rory McGuire
Nov 24, 2009
Brad Roberts
Nov 24, 2009
Nick Sabalausky
Nov 24, 2009
Walter Bright
November 24, 2009
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
November 24, 2009
On Tue, 24 Nov 2009 10:30:30 +0300, Andrei Alexandrescu <SeeWebsiteForEmail@erdani.org> 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

Think so, too.
November 24, 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

Yes, it works like that in Java.
November 24, 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


Definitely. I think the spec should state as a general rule that unreachable code is an error. Then more such checks can be added to DMD even after D2 is declared stable.

-Lars
November 24, 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
>> 
> Yes, it works like that in Java.


Yes, it works like that in C#.


November 24, 2009
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)
November 24, 2009
Andrei Alexandrescu <SeeWebsiteForEmail@erdani.org> 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
> 

Yes, I think so too.

And shouldn't the following also produce a compile-time error?

void main() {
	try {

	} catch (Exception e) {

	}
}


November 24, 2009
Michal Minich wrote:
>> 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
>>>
>> Yes, it works like that in Java.
> 
> 
> Yes, it works like that in C#.
> 
> 

Yes, it works like that in D.
November 24, 2009
"Lars T. Kyllingstad" <public@kyllingen.NOSPAMnet> wrote in message news:heg9jk$7f3$1@digitalmars.com...
>
> I think the spec should state as a general rule that unreachable code is an error.

Disagree very much with this. I don't want to have to carefully comment out temporarily-dead code when I'm inserting debugging breaks and returns. That'd be a real PITA.


November 24, 2009
On Tue, 24 Nov 2009 18:31:27 +0300, Nick Sabalausky <a@a.a> wrote:

> "Lars T. Kyllingstad" <public@kyllingen.NOSPAMnet> wrote in message
> news:heg9jk$7f3$1@digitalmars.com...
>>
>> I think the spec should state as a general rule that unreachable code is
>> an error.
>
> Disagree very much with this. I don't want to have to carefully comment out
> temporarily-dead code when I'm inserting debugging breaks and returns.
> That'd be a real PITA.
>
>

More or less I agree. That's what -w option is for.
« First   ‹ Prev
1 2