Because from what I understand, an Error is something you should
not be catching and represents something unrecoverable. And it
the docs say that it's unsafe to continue execution. But the
following code is very recoverable and I don't see how it's
unsafe to continue executing:
import optional;
import core.exception: SwitchError;
enum Enum : string {
one = "one", two = "two"
}
Optional!Enum makeEnum(string value) {
try {
final switch (value) {
case Enum.one: return some(Enum.one);
case Enum.two: return some(Enum.two);
}
} catch (SwitchError) {
return no!Enum;
}
}
unittest {
assert(makeEnum("one") == some(Enum.one));
assert(makeEnum("huh") == no!Enum);
}
Cheers,
- Ali