Handler for case when empty error is accessed.
1 static assert(!isDefaultConstructorEnabled!AsException); 2 static assert(hasOnErrorSet!(AsException, string)); 3 4 auto div(int a, int b) { 5 if (b != 0) return ok!(string, AsException)(a / b); 6 return err!(int, AsException)("oops"); 7 } 8 9 assert(div(10, 2) == 5); 10 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.