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

example/example.dart

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
150
pub points
26%
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