cast
means you're taking matters into your own hands, and you can do anything with it - useful, like ratchet freak said, for combining flags. (Though, in those cases, I like to give an exact type and explicit values to each item to be sure everything does what I want, so enum : ubyte { x = 1, y = 2, z = 4}, that kind of thing)
Anyway, there is a way to get runtime exceptions though in a case like this: use std.conv.to:
import std.conv;
import std.stdio;
void main() {
enum E {x, y, z}
E e;
writeln(e);
e = to!E(2); // gives z, whereas to!E(3) throws an exception
writeln(e);
}
Cool fact: to!E(string) also works. to!E("x") == E.x, and to!string(E.x) == "x".