Work effectively with AI coding agents. Understand them as language models running in a tool loop with limited context, which is why they guess, game the visible signal and report confidently. Recognise the shortcut and correctness tells in their code across Python, TypeScript/JavaScript, Rust, Java and Go, and know the damage each one does later. Verify changes instead of trusting them, review diffs fast for quality and security, judge when work is truly finished, and choose, design and steer tasks so agents can finish them well.
Error handling idioms across languages
card 4 of 6
Java: an empty catch after a compile error
The agent calls `Files.readString(path)`, and javac reports *unreported exception IOException*. The agent wraps the call in `try { … } catch (IOException e) {}` and returns `null`. **Tell:** an empty catch that appears right after a compile error. **Later cost:** a missing file turns into a `NullPointerException` in another class, with no trace of the path. **Better:** declare `throws IOException` if callers can react. Otherwise `throw new UncheckedIOException(e)`, which keeps the cause.
Terms on this card
- UncheckedIOException
- Java runtime (unchecked) exception that wraps an IOException, keeping it as the cause without forcing callers to catch it.
- NullPointerException
- Java runtime exception thrown when code uses a null reference as if it were an object.
- javac
- The Java compiler.
- compile error
- The compiler rejects the code, for example because of a missing method, so no test runs at all.
- `NullPointerException`
- Java's runtime error when code uses a reference that is null, for example by calling a method on it.
Lesson goal: Compare exceptions (Python, Java checked and unchecked, JS/TS), Result/Option with ? (Rust) and error values (Go). For each, say where an error should be handled versus propagated and what 'ignoring' an error looks like. ·
the whole lesson