Java Exceptions Catalog - Part 3: Collections & Concurrency
Comprehensive guide to data structure faults (java.util), multi-threaded executor and synchronization exceptions (java.util.concurrent), and mathematical rounding issues (java.math).
1. Collections & Utility Exceptions (java.util Package)
java.util.ConcurrentModificationException
Modifying a collection structural state (adding or removing elements) while iterating over it via a standard loop.
Iterator.remove(), Collection.removeIf(), or thread-safe collection structures like CopyOnWriteArrayList or ConcurrentHashMap.java.util.NoSuchElementException
Requesting the next element from an Iterator, Enumeration, or Optional.get() when no further elements exist.
iterator.hasNext() or optional.isPresent() / optional.orElseThrow().java.util.MissingResourceException
ResourceBundle cannot locate a requested property key or resource bundle file.
.properties files.java.util.InputMismatchException
Thrown by Scanner when a retrieved token does not match the pattern for the expected data type.
java.util.EmptyStackException
Invoking pop() or peek() on an empty java.util.Stack instance.
java.util.UnknownFormatConversionException
An unknown conversion specifier flag is passed to String.format() or System.out.printf().
java.util.FormatFlagsConversionMismatchException
An incompatible format flag and conversion specifier combination is passed to a formatter.
java.util.IllegalFormatPrecisionException
A negative precision value (other than -1) is supplied to a string format conversion.
java.util.IllegalFormatWidthException
A negative width value is supplied to a string format specifier.
java.util.MissingFormatArgumentException
The format string specifies a parameter index or conversion flag that lacks a matching argument.
java.util.DuplicateFormatFlagsException
Duplicate flags are provided inside a single format specifier argument.
java.util.IllegalFormatCodePointException
An invalid Unicode code point is passed to a character formatting conversion.
2. Multithreading & Concurrency (java.util.concurrent Package)
java.util.concurrent.RejectedExecutionException
An ExecutorService rejects a task submission because its bounded work queue is saturated or the pool has been shut down.
RejectedExecutionHandler (e.g., ThreadPoolExecutor.CallerRunsPolicy), or monitor thread pool capacity.java.util.concurrent.ExecutionException
Wrapper exception thrown when calling Future.get() on a task that aborted due to an internal uncaught exception.
exception.getCause() to debug the underlying task execution error.java.util.concurrent.CancellationException
Attempting to retrieve the result of a value-producing task (via Future.get()) that was explicitly cancelled.
future.isCancelled() prior to invoking get().java.util.concurrent.TimeoutException
A blocking operation (e.g., Future.get(timeout, unit) or lock acquisition) timed out before completing.
java.util.concurrent.BrokenBarrierException
Thrown when a thread attempts to wait upon a CyclicBarrier that has entered a broken state due to interruption or timeout.
java.util.concurrent.CompletionException
Unchecked wrapper exception thrown when a CompletableFuture task or stage completes exceptionally.
java.util.concurrent.locks.AbstractQueuedSynchronizer
Internal synchronizer exceptions arising from lock acquisition timeouts or corrupted state condition queues.
3. Math & Precision Exceptions (java.math Package)
java.lang.ArithmeticException (BigDecimal division)
Occurs when a BigDecimal division operation yields an inexact non-terminating decimal expansion without a specified rounding mode (e.g., 1 / 3).
RoundingMode (e.g., bigDecimal.divide(divisor, 2, RoundingMode.HALF_UP)).
No comments:
Post a Comment