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"]);
}
}