[Issue 6329] Out of range exceptions not thrown in certain cases

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sat Apr 7 13:40:24 PDT 2012


http://d.puremagic.com/issues/show_bug.cgi?id=6329



--- Comment #11 from Andrej Mitrovic <andrej.mitrovich at gmail.com> 2012-04-07 13:41:00 PDT ---
I've run into this issue yet again. And I've noticed something: If I compile
with '-g' then I get the exception thrown. Otherwise nothing is thrown and I
get back an exit code: -1073741819

Here's an example with Vladimir's AE library:

Use this test.xml file:
<Class file="somefile"></Class>

And this script:

import ae.utils.xml;
import std.path;
import std.file;
import std.stream;
import std.stdio;

void main()
{
    foreach (string entry; dirEntries(".", SpanMode.shallow))
    {
        if (entry.extension == ".xml")
        {
            Stream stream = new BufferedFile(entry);
            XmlNode document = new XmlDocument(stream);
            auto node = document.children[0];

            writeln(node.attributes["file"]);
            writeln(node.attributes["none"]);
        }
    }
}

Notice that "file" will exist but "none" does not, and this should throw a
RangeError.

So if I run 'rdmd -g test.d', I get:
core.exception.RangeError at test(20): Range violation
and a stack trace.

But if I run 'rdmd test.d' (without -g) I get the exit code '-1073741819'. I
can't even catch the error by using Throwable, it simply exits the app
altogether.

As it stands using dirEntries is completely unreliable for me, and this issue
keeps shooting me in the foot because I keep forgetting about it as I
innocently use the foreach loop without thinking.

And here's a way to force the range error without using -g:

import ae.utils.xml;
import std.path;
import std.file;
import std.stream;
import std.stdio;

void main()
{
    string[] entries;
    foreach (string entry; dirEntries(".", SpanMode.shallow))
    {
        if (entry.extension == ".xml")
        {
            entries ~= entry;
        }
    }

    foreach (entry; entries)
    {
        Stream stream = new BufferedFile(entry);
        XmlNode document = new XmlDocument(stream);
        auto node = document.children[0];

        writeln(node.attributes["file"]);
        writeln(node.attributes["nonexistent_key"]);
    }        
}

So basically the only safe way of using dirEntries is to save a list of files
and then do another foreach loop to process it.

I really hope we get this fixed. :/

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list