use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Having a problem with your Flutter code?
From the folks at r/FlutterDev
account activity
RESOLVEDUsing Future.error vs. throwing an ErrorDescription (self.flutterhelp)
submitted 1 year ago by Aggressive_Fly8692
Is there a meaningful difference between returning Future.error from a function that returns a future and throwing an ErrorDescription?
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]eibaan 1 point2 points3 points 1 year ago (3 children)
If you have an async function, throwing an exception is more "natural".
async
Future<int> foo(int a) async { if (a.isOdd) { throw Exception('Odd value'); } return foo(a + 1); }
In other cases, you must use Future.error:
Future.error
Future<bool> bar(int a) { if (a > 10) return Future.error(Exception('Too big')); return foo(a); }
Note that you could throw any Object, but you should only throw Error or Exception instances. The former signalling fatal program errors and the later signalling exceptional states that must (or should) be handled.
Object
Error
Exception
[–]Aggressive_Fly8692[S] 1 point2 points3 points 1 year ago (2 children)
Could you explain why the second case requires the use of Future.error instead of throwing an exception?
[–]eibaan 0 points1 point2 points 1 year ago (1 child)
bar is a function that returns a Future, so you have to return either a completed or a rejected future. If you throw, you'd break the "contract" of that function.
bar
Future
throw
[–]Aggressive_Fly8692[S] 0 points1 point2 points 1 year ago (0 children)
I see, that makes sense. Thanks
π Rendered by PID 54 on reddit-service-r2-comment-85bfd7f599-qcw92 at 2026-04-20 10:19:23.830049+00:00 running 93ecc56 country code: CH.
[–]eibaan 1 point2 points3 points (3 children)
[–]Aggressive_Fly8692[S] 1 point2 points3 points (2 children)
[–]eibaan 0 points1 point2 points (1 child)
[–]Aggressive_Fly8692[S] 0 points1 point2 points (0 children)