Errors for Darts
Errors in Dart cover how programs report and recover from failure. Dart separates Exceptions, which signal recoverable conditions you can catch, from Errors, which flag programming bugs. This unit also covers using the standard libraries and packages from pub.dev, since most error handling happens at the boundary with such code.
Stage: Async and Errors · Part of the Dart roadmap · Last reviewed 19 November 2026
What to learn in Errors
- Throw and catch exceptions with try, on, catch and finally
- Tell apart Exception types from Error types and when to catch each
- Define a custom exception class for your own domain
- Rethrow an exception while preserving its stack trace
- Import core libraries such as dart:io and dart:convert
- Add and import a package from pub.dev using pubspec.yaml
Errors interview questions
What is the difference between Exception and Error in Dart?
An Exception describes a condition a program may reasonably catch and handle, such as a FormatException. An Error indicates a bug in the code, such as a RangeError or StateError, and is generally not meant to be caught. Fix the cause instead.
How do you use on and catch together in Dart?
Use on to filter by exception type and catch to bind the exception and stack trace, as in on FormatException catch (e, s). You can chain several on clauses, then a final catch for anything else. Finally always runs afterwards.
Where Errors fits in the Dart roadmap
Errors belongs to the Async and Errors stage (beginner level). Time and failure.