Caffeinated Coder
Book an appointment
Lesson 11 · Objects

Exceptions

When a method cannot do its job, it throws an exception: an object that carries a message and a stack trace. Follow one through a real program: CheckAge(-5) throws an ArgumentException onto the heap, the runtime unwinds CheckAge's frame off the call stack, Main's catch handles it and prints "Age cannot be negative", and the finally block prints "done". Lines that never run are skipped.

12 min9 steps5 questionsIntermediate
Fig 11 · Interactive
Loading figure…
or ← →

Quiz Unlocks after the last step.