Skip to main content
Module 5 · Lesson 1 of 211/22 in the course~14 min
Module lessons (1/2)

Try-catch blocks and exceptions

Lesson preview5 hands-on exercises readyCourse Java · Module 5 — Exception Management

Checked vs unchecked exceptions, block order catch, multi-catch (A | B), custom exceptions and relaunch with cause.

What you'll learn in this lesson

  • Distinguish Checked Exceptions (IOException, handled or declared with throws) from Unchecked / RuntimeException (IllegalArgumentException, NullPointerException).
  • Trap specific errors by ordering catch blocks correctly and taking advantage of multi-catch (A | B).
  • Throw explicit exceptions (throw new) while always preserving the original cause (cause).

Overview

When an operation fails at runtime (file missing, input malformed, division by zero), Java throws an object Exception up the Stack until a compatible block catch handles it.

Java checks the catch blocks from top to bottom choosing the first compatible one: always put the most specific exceptions before Exception. The optional block finally runs in any case (success or error):

Sections covered in this lesson

  1. 11. Hierarchy Throwable: Checked vs Unchecked
  2. 22. Order of catch, finally and Multi-Catch (|)
  3. 33. Throwing Exceptions with throw new and Exception Chaining
  4. 44. Create a Lightweight Custom Exception
  5. 5Try it yourself
Pro Lesson · Module 5 — Exception Management

Unlock "Try-catch blocks and exceptions" and the full Course Java curriculum

Checked vs unchecked exceptions, block order `catch`, multi-catch (`A | B`), custom exceptions and relaunch with cause.

Unlock all 5 hands-on exercises in this lesson plus every advanced WebAssembly module with automated checks.

  • Instant access to all advanced modules in Course Java plus 17 more courses
  • Hands-on browser exercises with automated test suites and solutions
  • 14-day money-back guarantee processed via Paddle.com

14-day guarantee · Cancel anytimeModule 1, all 18 interactive games, and cheatsheets are always free.