Last update March 7, 2012

Doc Comments /




The following code prints "FileException" because the best matching catch clause seems to be determined at runtime, while equivalent code for C++ would print "Exception" instead because ex is declared as Exception.

import std.file;

int main(char[][] args)
    Exception ex = new FileException("Something");

    throw ex;
  catch (FileException exc)
  catch (Exception exc)

  return 0;


Shadowing by delegates

In the case where a variable in a delegate has the same name as a variable in the enclosing funtion, you say the variable in the delegate does not shadow the variable in the enclosing function and so there is no error.

I see your point since the delegate is implemented as a separate function. However, the point is to save confussion and the delegate is logically part of the enclosing function (and shares the same stack frame). It may make sence to not allow shadowing by delegates.


Empty statement blocks for while/if

Can you have empty statement blocks for while loops and if statements? e.g.

if (doit)

while (isItFinished()) ;

It would probably be beter if you could not for similar reasons to the for statement.


foreach grammar


why is ForeachType only defined as inout Type Identifier and Type Identifier but not also as in Type Identifier?

Because the default for the storage class is in DigitalMars:d/function.html#parameters

Correct, but you can explicitly use the in storage class for general functions.

for grammar

DigitalMars:d/statement.html#for (ThomasKühne)

If Initializer declares a variable, that variable's scope extends through the end of Statement.

Neither does this represent the actual implementation nor the general scoping rules.


FrontPage | News | TestPage | MessageBoard | Search | Contributors | Folders | Index | Help | Preferences | Edit

Edit text of this page (date of last change: March 7, 2012 20:26 (diff))