Stage 1 · Lesson 4 of 10
Exceptions and records
Java has two kinds of . Checked exceptions must be caught or declared, and the compiler forces you to do it. Unchecked ones, such as IllegalArgumentException, signal bugs or bad input.
Learn try, catch and finally. Learn try-with-resources too, which closes connections and streams for you automatically. Create your own exceptions for business errors, such as OrderNotFoundException.
will later turn that into a 404 in one place. are the other half of this topic. One line, record Order(long id, BigDecimal total) {}, gives you an unchangeable data class.
It comes with a , accessors, equals, hashCode and toString already written. That makes records ideal for request and response bodies.
Common trapcatching Exception, printing the and carrying on as if nothing happened.
A question to check yourself, an AI practice session and 2 cheat sheet entries come with the full roadmap. Unlock
Resources for this stage
Start with· follow one of these
- GuideFreeDev.java: Learn Java
Oracle · Beginner
The official path through modern Java: records, collections, generics and exceptions
- CourseFreeJava Programming MOOC
University of Helsinki · Beginner
Free Helsinki course with hundreds of graded exercises, the best way to get fluent
Practise
Keep handy
Also worth your time
The DNS, TCP, TLS and HTTP steps behind every request your backend will handle