Chained Catch Statements

Jonathan M Davis jmdavisProg at gmx.com
Mon Jan 30 17:19:10 PST 2012


On Tuesday, January 31, 2012 01:05:20 Andrej Mitrovic wrote:
> On 1/30/12, Era Scarecrow <rtcvb32 at yahoo.com> wrote:
> > If the compiler reorders the blocks for you
> 
> A warning, maybe. But I'm against compilers which try to be too smart
> and rewrite code to change its semantics. If there's something wrong
> with my code I want to know about it (warning or error) and fix it, I
> don't want the compiler rewriting bad code behind-the-scenes. That
> only encourages writing sloppy code, and I end up having to know
> implementation details of each compiler to really know what some
> function body actually does (it could be someone else's code and not
> just mine).

I see no reason why the compiler should be reordering anything here. That 
changes the semantics of the code. It's not like it's a great burden on the 
programmer to just reorder the blocks so that they're in the correct order. 
Having the compiler give a warning or error would be plenty, and a lot better 
than letting the programmer continue to screw up their code in ignorance. If 
they don't understand how the catch blocks work, they're likely to screw up 
more than just the order.

I do think that having the compiler complain when one catch block hides
another makes a lot of sense, but I think that that's as far as it should
go. It's the programmer's job to fix their code, not the compiler's.

- Jonathan M Davis


More information about the Digitalmars-d-learn mailing list