try_catch_error 1.0.0
try_catch_error: ^1.0.0 copied to clipboard
With the help this package you can pass a future function inside a try catch block in one line.
A simple package for try catch error handling.
Features #
- you can pass future function in try catch block in single line.
Getting started #
import 'package:try_catch_error/try_catch_error.dart';
Usage #
Future futureFunction() async {
final res = await Future.delayed(const Duration(seconds: 2), () {
// throw "some error";
return [1, 2, 3];
});
return res;
}
void main() async {
final res = await tryCatch(futureFunction: futureFunction);
if (res["data"] != null) {
print(res["data"]);
} else {
print(res["catch"]);
}
}