Exception Safe Programming

Saaa empty at needmail.com
Sun Feb 25 10:20:28 PST 2007


Maybe I still don't get it :/

I made this simple function (mostly stolen :)

void getPictureList(char[] dir, out char[][] files){
  isdir(dir);
  files = std.file.listdir(dir, "*.png");

  foreach (d; files)
  writefln(d);
  writefln(files.length);
  //if(files.length < 12) throw new Exception("Not enough images 
found(<12)");
}

When I uncomment the last line I get:
Error: pictures: The system cannot find the file specified.
(commented version doesn't generate any errors)

There are only 10 files so an exception should be trown, but not that one ! 
: )

-

I call the function in my main and at the end of my main there is:

scope(failure)
{
  writefln("Press the 'any' key to quit");
  getchar();
}

Why isn't this run in the uncommented version?

- 




More information about the Digitalmars-d-learn mailing list