tryAndWrap<RT extends Object, CT extends Exception, ET extends Exception> static method
Result<RT, ET>
tryAndWrap<RT extends Object, CT extends Exception, ET extends Exception>(
- RT tryAction(),
- ET customExceptionFactory(
- CT e
RT...return type
CT...catch exception type
ET...custom exception type
exception を throw する可能性のある function を実行し, もし exception が throw された 場合 その exception を catch し, 新しい custom exception に wrap する syntax sugar.
Implementation
static Result<RT, ET> tryAndWrap<
RT extends Object
,CT extends Exception
,ET extends Exception
>(
RT Function() tryAction,
ET Function(CT e) customExceptionFactory
) {
final classLocation = Result;
const functionLocation = 'tryAndWrap';
Map<String, dynamic> monitor = {};
Map<String, dynamic> debug = {};
List<Log> histories = [];
try {
final value = tryAction();
return Success(value, classLocation, functionLocation, monitor, debug, histories);
} on CT catch (e) {
final exception = customExceptionFactory(e);
return Failure(exception, classLocation, functionLocation, monitor, debug, histories);
}
}