Last update March 7, 2012

Doc Comments /
Statement



Statements

Examples

DigitalMars:d/statement.html#try

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)
{
  try
  {
    Exception ex = new FileException("Something");

    throw ex;
  }
  catch (FileException exc)
  {
    printf("FileException\n");
  }
  catch (Exception exc)
  {
    printf("Exception\n");
  }

  return 0;
}

Messages

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.

DavidO?

Empty statement blocks for while/if

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

if (doit)
else
{
    didNotDoIt();
}

while (isItFinished()) ;

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

DavidO?

foreach grammar

DigitalMars:d/statement.html#foreach

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.

Links


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))