Programming foundations

Stage 1 · Lesson 8 of 9

Exceptions and stack traces

Your first language

Java signals errors with . The , read from the top, gives the exception type, the message and the exact line. There are two kinds.

exceptions, such as IOException, are failures you should plan for, like a missing file. The compiler makes you either catch them or declare them with throws in the . Unchecked exceptions, such as NullPointerException or ArrayIndexOutOfBoundsException, usually mean a bug to fix rather than catch.

Use try, catch and finally for expected failures. Use , try (var reader = ...), to close files automatically when you are done. Catch the narrowest type you can, never leave a catch block empty, and throw IllegalArgumentException for bad input.

A question to check yourself, an AI practice session and 3 cheat sheet entries come when you add the roadmap to your account. Add it

Resources for this stage

Start with· follow one of these

  • CourseFree
    Java Programming MOOC

    University of Helsinki · Beginner

    Free Helsinki course with hundreds of auto-tested exercises; parts 1 to 8 cover this stage

  • GuideFree
    Dev.java: Learn Java

    Oracle · Beginner

    Official tutorials from the Java team: read the language basics path next to the MOOC

Practise

  • Small exercises in your language track, with free feedback from a human mentor

Keep handy

  • Quick syntax lookups and an online compiler for testing a snippet on a shared computer

Mark this stage as not done?