Disallow catch without parameter ("LastCatch")

grauzone none at example.net
Mon Oct 26 00:44:02 PDT 2009


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.



More information about the Digitalmars-d mailing list