Exception Handling in Dart: Chapter Overview

Exception Handling teaches you to keep a program running when something goes wrong.

In this chapter, you will:

  • catch problems with try, on, catch and finally
  • throw and rethrow problems, and read stack traces
  • write your own exception classes, and know Dart's built-in errors

What each lesson covers:

  • Exception Handling: How to catch errors with try, on, catch and finally, throw and rethrow them, write your own exceptions, and read Dart's built-in errors.

This chapter has 1 lesson. Plan on about 20 minutes, with 3 exercises to check what you learned. Every example is real Dart code: change it, run it again and compare the output, which is the fastest way to learn how each feature behaves.

Simple lesson: finish this chapter and a typo from a user will never crash your program again.

Lessons in this section

  1. Exception Handling

    How to catch errors with try, on, catch and finally, throw and rethrow them, write your own exceptions, and read Dart's built-in errors.

    • Catch exceptions with try, on, catch and finally
    • Throw, rethrow and create custom exceptions
    • Tell errors from exceptions and recognise the built-in ones