The same as visit, except that failure to handle types is checked at runtime.
Instead of failing to compile, tryVisit will throw an Exception if none of the handlers is able to handle the value contained in tu.
import std.exception : assertThrown; union U { int number; string text; } alias TU = TaggedUnion!U; auto tu = TU.number(42); tu.tryVisit!((int n) { assert(n == 42); }); assertThrown(tu.tryVisit!((string s) { assert(false); }));
See Implementation
The same as visit, except that failure to handle types is checked at runtime.
Instead of failing to compile, tryVisit will throw an Exception if none of the handlers is able to handle the value contained in tu.