Handler for case when empty error is accessed.
static assert(!isDefaultConstructorEnabled!AsException); static assert(hasOnErrorSet!(AsException, string)); auto div(int a, int b) { if (b != 0) return ok!(string, AsException)(a / b); return err!(int, AsException)("oops"); } assert(div(10, 2) == 5); assert(collectExceptionMsg!(Unexpected!string)(div(1, 0)) == "oops");
Hook implementation that behaves like a thrown exception. It throws Exception right when the Expected with error is initialized.
With this, one can easily change the code behavior between Expected idiom or plain Exceptions.