On this page
RuntimeException
Prev: `AutoCloseable` | Up: builtins | Next: `primitives`
Rel: builtins, Classes, Records & Sealed Hierarchies
Ref: Java Docs — RuntimeException
Tags: #public #prog #java #builtins #tier/core
Availability
Built-in / java.lang (java.lang Exception Base) — available with zero import statements.
Syntax & Overview
public class AppException extends RuntimeException
Base class for unchecked exceptions (not required in throws clauses), distinct from checked Exception subclasses.
Notes & Pitfalls
- Unchecked exception hierarchy: Does not require
throwsdeclarations (IllegalArgumentException,IllegalStateException,NullPointerException). - Use checked exceptions for recoverable caller failures and unchecked exceptions for programmer/contract bugs.
Example
static int requirePositive(int n) {
if (n <= 0) throw new IllegalArgumentException("must be > 0: " + n);
return n;
}
assert requirePositive(5) == 5;
Linked from
Related notes
- tuts/java/builtins/AutoCloseable Linked here; links to this page; shared tags: #builtins, #java, #prog, #tier
- tuts/java/builtins/primitives Linked here; links to this page; shared tags: #builtins, #java, #prog, #tier
- tuts/java/builtins Linked here; links to this page; shared tags: #builtins, #java, #prog
- tuts/java/language_and_oop/classes_records_and_sealed_hierarchies Linked here; shared tags: #java, #tier
- tuts/java/language_and_oop/exceptions_and_resource_management links to this page; shared tags: #java, #tier
- tuts/java/builtins/enum shared tags: #builtins, #java, #prog, #tier
- tuts/java/builtins/final shared tags: #builtins, #java, #prog, #tier
- tuts/java/builtins/finalize shared tags: #builtins, #java, #prog, #tier
- tuts/java/builtins/interface shared tags: #builtins, #java, #prog, #tier
- tuts/java/builtins/Object shared tags: #builtins, #java, #prog, #tier