tryCallSync<T> function
T?
tryCallSync<T>(
- T? call(), {
- T? defaultValue,
- T? onSuccessValue,
- T? onErrorValue,
Tries to performa a call
synchronously.
- If
onSuccessValue
is defined it overwrites thecall
returned value. - If
onErrorValue
is defined it will be returned in case of error. - Returns
defaultValue
ifcall
returnsnull
andonSuccessValue
oronErrorValue
arenull
.
Implementation
T? tryCallSync<T>(T? Function() call,
{T? defaultValue, T? onSuccessValue, T? onErrorValue}) {
try {
var ret = call();
return onSuccessValue ?? ret ?? defaultValue;
} catch (_) {
return onErrorValue ?? defaultValue;
}
}