exceptions
27 tutorials tagged “exceptions”.
- ConcurrentModificationException in JavaConcurrentModificationException is thrown when a collection is changed while it is being iterated. Learn why it happens, a surprising case, and four fixes.
- OutOfMemoryError Types and CausesEach OutOfMemoryError message names the memory area that ran out. Learn the heap, Metaspace, direct buffer and thread variants and how to fix each.
- AutoCloseable vs CloseableTwo interfaces with one close() method: how they differ in exceptions and repeated calls, which JDK classes use each, and which your class should implement.
- Chained Exceptions in JavaWrap a low-level exception in a meaningful one without losing the original: the cause parameter, getCause, and turning checked exceptions into unchecked.
- Checked vs Unchecked ExceptionsWhy the compiler forces you to handle some exceptions and not others, the catch-or-declare rule, and how to decide which kind to use.
- Common Errors in JavaOutOfMemoryError and StackOverflowError: what fills the heap or the stack, how to reproduce both safely, and why you fix them instead of catching them.
- Common Exceptions in JavaThe runtime exceptions you'll meet most, from NullPointerException to ClassCastException: what causes each and how to prevent it.
- Custom Exceptions in JavaCreate your own exception classes: checked or unchecked, the constructors to provide, extra fields, and a number-parsing utility that ties it all together.
- Exception Handling Best PracticesTwelve habits for exceptions that help instead of hurt: fail fast, catch specific types, never swallow, keep the cause, close with try-with-resources.
- Exception Handling in JavaWhat an exception is, what happens when nobody handles one, and how try-catch lets a program recover from bad input and failures instead of crashing.