Code:

===================================
import std.conv;
import std.regex;

struct A
{
        int field1;
        int field2;
        
        this(int field1, int field2)
        {
                if(field1 > field2)
                        throw new Exception("This is illegal!");
        }
        
        this(string str)
        {
                if(str.match(ctRegex!(`^[0-9]{4}-[0-9]{2}`)))
                        this(str[0..4].to!int, str[5..7].to!int);
                else
                        throw new Exception("Invalid string");
        }
}

void main()
{
        A(2004, 43);
        A("2004-43");
}
===================================

This throws a compilation error:

main.d(17): Error: one path skips constructor
main.d(15): Error: return without calling constructor

Why do I need the constructor call, if I throw the exception anyway? Is this a bug?

Reply via email to