try_catch 1.0.1 try_catch: ^1.0.1 copied to clipboard
try call a async function , return value same as the function , on exception print error and ignore
try_catch #
try call a async function , return value same as the function , on exception print error and ignore
use #
import 'package:try_catch/async.dart';
Future<int> test1() async {
await Future.delayed(Duration(seconds: 3));
throw Exception('test error');
}
Future<int> test2() async {
await Future.delayed(Duration(seconds: 1));
return 1;
}
void main() async {
print('await sleep 3 seconds');
print(await tryCatch(() => test1())); //null
print(await tryCatch(() => test2())); //1
print('done');
}