This is my exception class. Exception class has been implemented by the abstract exception class of flutter. Am I missing something?
class FetchDataException
To handle errors in an async and await function, use try-catch:
Run the following example to see how to handle an error from an asynchronous function.
Future printOrderMessage() async {
try {
var order = await fetchUserOrder();
print('Awaiting user order...');
print(order);
} catch (err) {
print('Caught error: $err');
}
}
Future fetchUserOrder() {
// Imagine that this function is more complex.
var str = Future.delayed(
Duration(seconds: 4),
() => throw 'Cannot locate user order');
return str;
}
Future main() async {
await printOrderMessage();
}
Within an async function, you can write try-catch clauses the same way you would in synchronous code.