On Wednesday, 17 October 2018 at 00:12:13 UTC, H. S. Teoh wrote:
I'm not sure what's the reasoning behind the saying that
throwing exceptions in ctors is bad, but exceptions are exactly
the kind of thing designed for handling this sort of situation.
If the parser detects a problem early (i.e., at construction
time, rather than the first call to .front), why not report the
problem early instead of waiting?
I think I must have confused constructors with destructors there.
Walter made this comment:
"Throwing in a destructor is a nightmare, it makes my brain hurt
just trying to figure out what 'should' happen. I've proposed
before that destructors should be nothrow."
https://issues.dlang.org/show_bug.cgi?id=14903
I couldn't find anything about nothrow constructors, so it might
be just fine.
Throwing exceptions to early is a problem when you do something
like this:
```
auto tokens = Lexer(source).handle!(ParseException,
RangePrimitive.front, (e, r) => Token.error);
```
https://dlang.org/phobos/std_exception.html#.handle
It's unexpected that the exception will be thrown one token in
advance.
Interesting solution for your problem with byLine by the way.