import std.traits: CommonType;
nothrow CommonType!(T1, T2) ifThrown(E : Throwable = Exception, T1, T2)(lazy scope T1 expression, scope T2 expression2)
static assert(!is(typeof(return) == void),
"The error handler's return value("
") does not have a common type with the expression("
int throwIfNot42(int x) {
import std.exception : enforce;
enforce(x == 42, "some error");
nothrow string foo(int x, string def) {
import std.format: format;
return format("%d", throwIfNot42(x)).ifThrown(def);
import std.stdio: writeln;
writeln(foo(42, "error"));
writeln(foo(43, "error"));