0Pricing
Dart Academy · Lesson

on Clauses and Exception Types

Catch specific errors precisely.

Not All Errors Are Equal

A file error and a format error are different problems. Dart lets you catch them by type so each gets the right response. 🎯

The on Keyword

Use on to catch only one exception type. The block runs solely when that specific kind of error is thrown.

try {
  parse();
} on FormatException {
  print('Bad format');
}

All lessons in this course

  1. throw, try, and catch
  2. on Clauses and Exception Types
  3. finally and Guaranteed Cleanup
  4. Custom Exceptions and rethrow
← Back to Dart Academy