try_catch 1.0.2 copy "try_catch: ^1.0.2" to clipboard
try_catch: ^1.0.2 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/init.dart';

Future<int> test1() async {
  await Future.delayed(Duration(seconds: 1));
  throw Exception('test error');
}

Future<int> test2() async {
  await Future.delayed(Duration(seconds: 1));
  return 1;
}

void main() async {
  print('await sleep 1 seconds');
  var r = await tryCatch(() => test1());
  print(r); //null
  print(await tryCatch(() => test2())); //1
  print('done');
}

0
likes
130
pub points
5%
popularity

Publisher

verified publisherrmw.link

try call a async function , return value same as the function , on exception print error and ignore

Repository (GitHub)
View/report issues

Documentation

API reference

License

MPL-2.0 (LICENSE)

More

Packages that depend on try_catch