0PricingLogin
Dart Academy · Lesson

throw, try, and catch

Detect and respond to failures.

When Things Go Wrong

Programs hit problems: bad input, missing files, broken math. Dart signals these with an exception instead of silently misbehaving. 🚨

Throwing an Exception

You raise a problem yourself with throw. It stops normal flow right where it happens and hands control off to a handler.

throw Exception('Something failed');

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