Skip to content

Instantly share code, notes, and snippets.

@RyanDsilva
Created June 26, 2022 09:14
Show Gist options
  • Save RyanDsilva/1f26f273bbecd2a2c28481c672bb0b85 to your computer and use it in GitHub Desktop.
Save RyanDsilva/1f26f273bbecd2a2c28481c672bb0b85 to your computer and use it in GitHub Desktop.
Try-Catch and Error Handling in Flutter
import 'package:flutter/material.dart';
Future<dynamic> functionThatThrowsException() async {
// some code
throw Exception('Could not perform operation.');
}
Future<void> testFunction() async {
try {
var x = await functionThatThrowsException();
// do something with x
} catch (e) {
debugPrint(e.toString());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment