Created
June 26, 2022 09:14
-
-
Save RyanDsilva/1f26f273bbecd2a2c28481c672bb0b85 to your computer and use it in GitHub Desktop.
Try-Catch and Error Handling in Flutter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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