try_catch 1.0.0 copy "try_catch: ^1.0.0" to clipboard
try_catch: ^1.0.0 copied to clipboard

outdated

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 try_catch(() => test1())); //null
  print(await try_catch(() => test2())); //1
  print('done');
}

0
likes
0
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

License

unknown (license)

More

Packages that depend on try_catch