Mobile development

Stage 1 · Lesson 7 of 10

Exceptions and error handling

Dart fundamentals

splits failures into two kinds. An Exception is a failure you expect and should handle, such as a FormatException from bad input. An Error is a programming mistake, such as a RangeError, that you fix rather than catch.

Learn try, on SomeException catch (e), finally and rethrow. Throw your own exception with a useful message. Catch where you can do something, such as showing a retry message, not in every function. code, which waits for results, has its own rule.

Common trapThe trap in async code is a Future that is never awaited: its error does not reach your try block at all and appears only as an unhandled error in the logs, if you look.

A question to check yourself, an AI practice session and 2 cheat sheet entries come with the full roadmap. Unlock

Resources for this stage

Start with

  • GuideFree
    Dart Language Tour

    Google · Beginner

    The official tour: read it in order and rerun every example in DartPad

Practise

  • Dart, TypeScript, Kotlin and Swift tracks with small exercises and free mentor feedback

Keep handy

  • Its Dart tutorial pages work as a quick lookup while you do the tour

Also worth your time

Mark this stage as not done?