tryAndCatch<RT extends Object, ET extends Exception> static method
RT...return type
ET...exception type
tryAction を実行し,
もし exception or Failure が throw された 場合
それ を catch し
返す syntax sugar.
catch した Failure の log を渡すために log は必須.
Implementation
static Danger<RT, ET> tryAndCatch<
RT extends Object
,ET extends Exception
>(
RT Function() tryAction,
Log log,
) {
// final log = Log(classLocation: Danger, functionLocation: 'tryAndCatch');
try {
final value = tryAction();
return Success(value, log);
} on ET catch (e) {
return Failure(e, log);
} on Failure<Object, ET> catch (e) {
log.add(e);
return Failure(e.wrapped, log);
}
}