Member-only story

Best Practices In Flutter Error Handling

Fred Grott
4 min readDec 26, 2021

--

Flutter is a bit uneven as far as error handling. Future’s have an API to catch an error, but functions often do not call that API. And there in fact is a better way to call a Future and get the exception processer rather than the catch method boilerplate.

In other words, it will be a hacker type of work-around. But, it does work.

Let’s start off with the FailureException class.

Failure Exception Class

This is just typically implements the Exception class:

And with that, we can first make some guards to ensure untrusted functions always throw exceptions upon error:

And with that same Failure Exception class we can write an extension to extend the Either Task in Dartz:

--

--

Fred Grott
Fred Grott

No responses yet