Disallow catch without parameter ("LastCatch")
Leandro Lucarella
llucax at gmail.com
Tue Oct 27 17:47:37 PDT 2009
grauzone, el 26 de octubre a las 08:44 me escribiste:
> Leandro Lucarella wrote:
> >grauzone, el 25 de octubre a las 12:09 me escribiste:
> >>Right now, you can catch every exception with "try { something; }
> >>catch { somethingelse; }".
> >>
> >>Can we get rid of this abomination before D2 is finalized? I claim
> >>that it's completely useless, and even more so, every single use of
> >>this is a bug.
> >
> >Why every use of this is a bug?
>
> Because you most likely catch more exception types than you really
> want. For example, a novice programmer is likely to write something
> like this:
>
> int x;
> try {
> x = convert(somestring);
> } catch {
> //convert throws some exception if convert() fails
> return -1;
> }
>
> This is a bug, because catch might catch and *hide* a runtime error
> like failing assertions. The programmer really wanted to write
> "catch (ConversionException e)". Even if he wrote "catch (Exception
> e)", he wouldn't catch runtime errors, and the code would be safe.
OK, I see. What about rewriting:
try {
foo();
} catch {
something();
}
As:
try {
foo();
} catch (Exception) {
something();
}
(I mean the compiler)?
I think a catch all is a nice feature for quick&dirty scripts, it would be
nice to keep it and fix the semantics.
--
Leandro Lucarella (AKA luca) http://llucax.com.ar/
----------------------------------------------------------------------
GPG Key: 5F5A8D05 (F8CD F9A7 BF00 5431 4145 104C 949E BFB6 5F5A 8D05)
----------------------------------------------------------------------
Y cuando llegamos a nuestro hogar ella saca de su bolsillo derecho un
casete de Ricardo Montaner y nos dice: "Ponelo! Ponelo!"; nos
desilusionamos un poco, pero a esa altura... Todo da igual.
-- Sidharta Kiwi
More information about the Digitalmars-d
mailing list