Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Error handling in Flutter
Search
Enzo Lizama Paredes
May 22, 2020
Programming
110
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Error handling in Flutter
Enzo Lizama Paredes
May 22, 2020
More Decks by Enzo Lizama Paredes
See All by Enzo Lizama Paredes
BDD in Flutter
enzoftware
0
94
Adding Flutter to an existing Android/iOS app
enzoftware
0
170
Flutter flavors
enzoftware
0
86
Flutter CI/CD with Fastlane
enzoftware
0
88
Flutter Animations
enzoftware
0
67
Productivity tools 4 developers
enzoftware
0
53
OpenCV + Android
enzoftware
1
72
Anko Superpowers
enzoftware
0
81
Mobile Vision API + Android
enzoftware
0
71
Other Decks in Programming
See All in Programming
私のClaude Code活用法 (個人開発編) - PHPerKaigi mini #4(2026/08/24)
panda_program
1
160
関東Kaggler会_NVIDIA_Nemotron_コンペ_振り返り
rick_ds
0
720
思考垂れ流し開発 ~音声入力 × AIエージェント × 開発ハーネスによる試行錯誤~
npostring
0
170
複数の Claude Code が"放置"されてしまう問題をCLI ダッシュボードを自作して解決した話
sumihiro3
1
730
AIの中の人になってみる
htkym
0
120
AI Readyの正体はデータマネジメントだ メダリオン2.0の最前線
freee
PRO
0
380
Go 1.27からのGODEBUG / Go 1.27 リリースパーティ #go127party
mazrean
0
220
Press start. Python's next generation.
willingc
PRO
3
130
「寝てても仕事が進む」Claude Codeで組む第二の脳
tomoyafujita2016
0
360
リアルな遅延を測る仕様
kota_yata
1
130
typoなんかねぇよ
raspython3
0
550
<title><a id="</title>君はこのHTMLをパースできるか"></a></title> #雑LT_study
pizzacat83
0
180
Featured
See All Featured
Learning to Love Humans: Emotional Interface Design
aarron
275
41k
Collaborative Software Design: How to facilitate domain modelling decisions
baasie
1
290
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
133
19k
We Are The Robots
honzajavorek
0
310
Claude Code のすすめ
schroneko
67
230k
Abbi's Birthday
coloredviolet
3
9.5k
Self-Hosted WebAssembly Runtime for Runtime-Neutral Checkpoint/Restore in Edge–Cloud Continuum
chikuwait
0
740
Evolution of real-time – Irina Nazarova, EuRuKo, 2024
irinanazarova
9
1.5k
Gemini Prompt Engineering: Practical Techniques for Tangible AI Outcomes
mfonobong
2
500
Ruling the World: When Life Gets Gamed
codingconduct
0
310
The Power of CSS Pseudo Elements
geoffreycrofte
82
6.5k
Easily Structure & Communicate Ideas using Wireframe
afnizarnur
194
17k
Transcript
Enzo Lizama Error handling in Flutter @enzoftware
KotlinConf 2019: Error Handling Strategies for Kotlin Programs by Nat
Pryce & Duncan McGregor What is failure?
None
Programs can go wrong for so many reasons • Invalid
input ◦ Strings with invalid values ◦ Numbers out of range ◦ Unexpectedly null pointers exceptions • External failure ◦ File not found ◦ Timeouts • Programming errors ◦ Array out of bound ◦ Invalid state • System error ◦ Out of memory
https://dart.dev/guides/libraries/library-tour#exceptions Exceptions are considered conditions that you can plan ahead
for and catch. Errors are conditions that you don’t expect or plan for.
https://flutter.dev/docs/testing/errors How Flutter handle errors
None
FlutterError.onError = (FlutterErrorDetails details) { FlutterError.dumpErrorToConsole(details); if (kReleaseMode) { exit(1);
// Report problem and track it } };
/// This is an [FlutterErrorDetails], appears instead of the red
screen /// to avoid scare the users ErrorWidget.builder = (FlutterErrorDetails details) => CustomErrorWidget(); ... class CustomErrorWidget extends StatelessWidget { @override Widget build(BuildContext context) { // Your custom error widget } }
/// This is an [FlutterErrorDetails], appears instead of the red
screen /// to avoid scare the users ErrorWidget.builder = (FlutterErrorDetails details) => CustomErrorWidget(); ... class CustomErrorWidget extends StatelessWidget { @override Widget build(BuildContext context) { // Your custom error widget } }
An example of error handling in Flutter A strategy
class Failure { final String message; final int statusCode; Failure(this.message,
this.statusCode); @override String toString() => "Error $statusCode. $message."; }
Future<List<HotelModel>> getHotels() async { try { final data = await
http.get(_baseUrl + _endPoint); final responseList = json.decode(data.body); return [for (final hotel in responseList) HotelModel.fromJson(hotel)]; } on SocketException { throw Failure("No internet connection", 400); } on HttpException { throw Failure("Not found request", 404); } on FormatException { throw Failure("Invalid JSON format", 666); } catch (e) { throw Failure("Unknown error", 888); } }
Future<List<HotelModel>> getHotels() async { try { final data = await
http.get(_baseUrl + _endPoint); final responseList = json.decode(data.body); return [for (final hotel in responseList) HotelModel.fromJson(hotel)]; } on SocketException { throw Failure("No internet connection", 400); } on HttpException { throw Failure("Not found request", 404); } on FormatException { throw Failure("Invalid JSON format", 666); } catch (e) { throw Failure("Unknown error", 888); } }
void retrieveHotels() async { try { _hotels = await repository.fetchHotels();
} on Failure catch (e) { _failure = e; } notifyListeners(); }
if (hotelBloc.failure != null) { return Center(child: Text(hotelBloc.failure.toString())); } ...
// The other widgets
Catcher Catcher is Flutter plugin which automatically catches error/exceptions and
handle them. Catcher offers mutliple way to handle errors https://pub.dev/packages/catcher
Enzo Lizama • https://github.com/enzoftware/hotel_booking_app • https://www.youtube.com/watch?v=pvYAQNT4o0I • https://flutter.dev/docs/testing/errors Utils resources
Thanks! @enzoftware