February 25, 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?

-


February 25, 2007
Saaa wrote:
> 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 ! : )

Somewhere in your program you're trying to open a file called "pictures" which is non-existent (at least where the system is looking) causing an exception.

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

Scope guards are excecuted in the reverse order of where they're declared. E.g., using the thrower() function from my last example:

void main()
{
	scope(exit) { writefln(); } //newline
	scope(failure)
	{
		writef("scope guards."); //Note: writef (no ln) doesn't add '\n'
	}
	scope(failure)
	{
		writef("of ");
	}
	scope(failure)
	{
		writef("an example ");
	}
	thrower();
	scope failure(failure)
	{
		writef("This is ");
	}
}

This will print:

an example of scope guards.
February 25, 2007
> Saaa wrote:
>> 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 ! : )
>
> Somewhere in your program you're trying to open a file called "pictures" which is non-existent (at least where the system is looking) causing an exception.

Yes the dir is 'pictures', but the program runs perfectly with that last
line commented out. ?
I'd expect it to say:
Error: Not enough images found(<12)

>
>>
>> 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?
>
> Scope guards are excecuted in the reverse order of where they're declared. E.g., using the thrower() function from my last example:
>
> void main()
> {
> scope(exit) { writefln(); } //newline
> scope(failure)
> {
> writef("scope guards."); //Note: writef (no ln) doesn't add '\n'
> }
> scope(failure)
> {
> writef("of ");
> }
> scope(failure)
> {
> writef("an example ");
> }
> thrower();
> scope failure(failure)
> {
> writef("This is ");
> }
> }
>
> This will print:
>
> an example of scope guards.
:)
Thanks again. Somehow I keep thinking of scope failure an a property of the
scope. But that analogy only works if the scope failure is actually read. I
had it at the end of my main (never read :)


February 25, 2007
Saaa wrote:
> Yes the dir is 'pictures', but the program runs perfectly with that last line commented out. ?
> I'd expect it to say:
> Error: Not enough images found(<12)
> 

Without seeing more of your program I can't tell what's going on.  You're right that it should be throwing the "not enough images found" exception, at least based on the snippet you posted.  Are you catching the "not enough images found" exception anywhere?
February 25, 2007
> Saaa wrote:
>> Yes the dir is 'pictures', but the program runs perfectly with that last
>> line commented out. ?
>> I'd expect it to say:
>> Error: Not enough images found(<12)
>>
>
> Without seeing more of your program I can't tell what's going on.  You're right that it should be throwing the "not enough images found" exception, at least based on the snippet you posted.  Are you catching the "not enough images found" exception anywhere?

That is the whole code.. I've stripped it bare. Only a main calling that function:

void main()
{
 char[][] files;
 getPictureList("pictures",files);
}


February 25, 2007
Saaa wrote:
> That is the whole code.. I've stripped it bare. Only a main calling that function:
> 
> void main()
> {
>  char[][] files;
>  getPictureList("pictures",files);
> } 
> 

Ah, I found the problem.  You're trying to list the contents of a directory that doesn't exist.  The error message isn't very clear, but that's the problem.  I don't know why commenting out the line with the throw is changing the behavior of the program, because it shouldn't.
February 25, 2007
I was that far myself :)
It is that I can list everything in that dir when that line is commented out
(everything working fine)

I too found the error a bit strange, but I thought I shouldn't complain :D

> Saaa wrote:
>> That is the whole code.. I've stripped it bare. Only a main calling that function:
>>
>> void main()
>> {
>>  char[][] files;
>>  getPictureList("pictures",files);
>> }
>
> Ah, I found the problem.  You're trying to list the contents of a directory that doesn't exist.  The error message isn't very clear, but that's the problem.  I don't know why commenting out the line with the throw is changing the behavior of the program, because it shouldn't.


February 25, 2007

Saaa wrote:
> I was that far myself :)
> It is that I can list everything in that dir when that line is commented out
> (everything working fine)
> 
> I too found the error a bit strange, but I thought I shouldn't complain :D
> 
>> Saaa wrote:
>>> That is the whole code.. I've stripped it bare. Only a main calling that function:
>>>
>>> void main()
>>> {
>>>  char[][] files;
>>>  getPictureList("pictures",files);
>>> }
>> Ah, I found the problem.  You're trying to list the contents of a directory that doesn't exist.  The error message isn't very clear, but that's the problem.  I don't know why commenting out the line with the throw is changing the behavior of the program, because it shouldn't.

I've had some *really* bizarre problems with some Exceptions lately.  I made the huge mistake of upgrading the D compiler when I had a working project... spent a week trying to track down a weird bug only to discover that for some reason, D was trying to memset 1.5GB of memory at program startup, and then throwing Win32 exceptions every time I tried to use a string as part of an Exception!

Tried to reduce it to a test case, but of course, I couldn't reproduce the problem...  *grumble grumble*

Sorry, just needed to vent a little.  A week staring at assembler and WinDbg only to discover D is doing something strange will do that :P

	-- Daniel

-- 
Unlike Knuth, I have neither proven or tried the above; it may not even make sense.

v2sw5+8Yhw5ln4+5pr6OFPma8u6+7Lw4Tm6+7l6+7D i28a2Xs3MSr2e4/6+7t4TNSMb6HTOp5en5g6RAHCP  http://hackerkey.com/
February 26, 2007
Saaa wrote
> When I uncomment the last line I get:
> Error: pictures: The system cannot find the file specified.
Not confirmed: DMD 1.007/WinXP32.

-manfred
February 26, 2007
Sorry for wasting everybody's time..
Every time I wanted to see what went wrong I ran through commandline and as
my pictures get read in relative.... ah well you'll get it :)

At least Daniel found this thread useful ; )


> Not confirmed: DMD 1.007/WinXP32.
>
> -manfred