Scrivio Interview library
ConceptFoundations7 min read · updated 12 November 2026

Name common standard unchecked exceptions in the JDK (IllegalArgumentException, IllegalStateException, UnsupportedOperationException, IndexOutOfBoundsException, ConcurrentModificationException, ArithmeticException) and when your own code should throw each one.

Throw IllegalArgumentException when a caller passes an invalid argument value, IllegalStateException when the object is not in a state that allows the call, such as a closed resource, and UnsupportedOperationException when the operation is not supported at all, as with List.of(...).add(...). IndexOutOfBoundsException is for an index outside the valid range, and Objects.checkIndex throws it for us; ConcurrentModificationException comes from fail-fast iterators, and ArithmeticException from integer division by zero or overflow in Math.addExact. Reusing these makes an API familiar; domain errors get their own custom exceptions.

Why this question is asked

Every API we write has to say "you called me wrongly" in some way, and the JDK already provides a vocabulary for it. When we use those standard exceptions consistently, other developers understand our failures at a glance, because they have seen the same types from the JDK thousands of times. Interviewers ask this to check that we know the difference between the common ones, especially IllegalArgumentException versus IllegalStateException, which people often mix up. In this answer, we will recap what unchecked exceptions are, go through each standard exception with an example and the rule for when our own code should throw it, and finish with when a custom exception is the better choice.

1A Quick Recap of Unchecked Exceptions

Unchecked exceptions are subclasses of RuntimeException. The compiler does not force callers to catch or declare them, because they usually signal a programming mistake, such as passing a bad value or calling a method at the wrong time, rather than a condition the caller should plan for. The right response to them is normally to fix the calling code, not to catch the exception.

The standard ones in java.lang and java.util each describe a particular kind of mistake. Choosing the right one is a small act of communication: the type alone tells the caller what they did wrong.

Standard unchecked exceptions and when to throw them
ExceptionMeaningTypical source
IllegalArgumentExceptionthis argument value is invalidnegative quantity, bad format
IllegalStateExceptionthe object cannot do this nowusing a closed resource, wrong lifecycle step
UnsupportedOperationExceptionthis operation is never supported hereList.of(...).add(...)
IndexOutOfBoundsExceptionindex outside the valid rangelist.get(10) on 3 elements, Objects.checkIndex
ConcurrentModificationExceptioncollection changed during iterationfail-fast iterators
ArithmeticExceptioninvalid integer arithmeticx / 0, Math.addExact overflow

2IllegalArgumentException: The Value Is Wrong

We throw IllegalArgumentException when a caller passes a value that the method cannot accept: a negative quantity, a percentage over 100, a date range whose end is before its start. The problem is in the argument itself, and the same call with a different value would work.

Java
public Money discount(Money price, int percent) {
if (percent < 0 || percent > 100) {
throw new IllegalArgumentException("percent must be between 0 and 100, was " + percent);
}
return price.multiply(100 - percent).divide(100);
}
discount(Money.of(50), 120); // IllegalArgumentException: percent must be between 0 and 100, was 120

Notice that the message names the rule and the actual value. That makes the bug obvious from the log line alone. For a null argument, the convention is NullPointerException from Objects.requireNonNull(value, "name"), which is itself a standard choice.

3IllegalStateException: The Object Is Not Ready

IllegalStateException means the arguments may be fine, but the object is in a state where the call is not allowed. A connection that has been closed, a builder that has already built, an order that has already shipped and is asked to change its address: in each case the same call would have worked earlier or will work later, but not now.

Java
class ReportWriter implements AutoCloseable {
private boolean closed;
public void write(String line) {
if (closed) throw new IllegalStateException("ReportWriter is closed");
// ... write the line
}
public void close() { closed = true; }
}
ReportWriter w = new ReportWriter();
w.close();
w.write("total: 42"); // IllegalStateException: ReportWriter is closed

A simple way to choose between the two is to ask what would make the call succeed. If a different argument would, it is IllegalArgumentException. If the same argument would work with the object in a different state, it is IllegalStateException.

4UnsupportedOperationException: Never Supported Here

UnsupportedOperationException says that this object does not support the operation at all, in any state. The best-known example is the unmodifiable collections returned by List.of, Set.of, Map.of and Collections.unmodifiableList: they implement the full List interface, including add and remove, but those methods always throw.

Java
List<String> names = List.of("ann", "bob");
names.add("cy"); // UnsupportedOperationException
List<String> copy = new ArrayList<>(names);
copy.add("cy"); // works: [ann, bob, cy]

We throw it in our own code when we implement an interface but deliberately do not support some of its methods, such as a read-only repository that implements a general interface. It should be documented, because callers cannot see it in the type.

5IndexOutOfBoundsException, ConcurrentModificationException and ArithmeticException

IndexOutOfBoundsException means an index is outside the valid range, from 0 to size minus 1. Lists throw it from get and set, and arrays throw its subclass ArrayIndexOutOfBoundsException. In our own code we rarely need to write the check by hand: Objects.checkIndex(index, length) throws it with a standard message, and the JIT treats it as an intrinsic, so it is cheap.

ConcurrentModificationException is thrown by the fail-fast iterators of collections such as ArrayList and HashMap when the collection is structurally changed during iteration other than through the iterator itself. Despite its name, it most often happens in a single thread. We do not normally throw it ourselves; we fix the code by using iterator.remove() or removeIf.

ArithmeticException is thrown for integer division or remainder by zero, and by the exact arithmetic methods such as Math.addExact and Math.multiplyExact when a result overflows. Floating-point division by zero does not throw; it produces Infinity or NaN.

Java
Objects.checkIndex(5, 3); // IndexOutOfBoundsException: Index 5 out of bounds for length 3
List<Integer> nums = new ArrayList<>(List.of(1, 2, 3, 4));
for (Integer n : nums) {
if (n % 2 == 0) nums.remove(n); // ConcurrentModificationException on the next iteration
}
nums.removeIf(n -> n % 2 == 0); // works: [1, 3]
int a = 10 / 0; // ArithmeticException: / by zero
Math.addExact(Integer.MAX_VALUE, 1); // ArithmeticException: integer overflow
double d = 10.0 / 0; // Infinity, no exception

6When to Define a Custom Exception Instead

Standard exceptions describe misuse of an API: bad arguments, bad timing, unsupported calls. They are the right choice in general-purpose code, utilities and libraries, and reusing them makes our API feel familiar because developers already know what they mean.

Domain errors are different. "Order not found", "payment declined" or "stock reserved by another order" are not programming mistakes; they are business situations that a handler may want to map to a specific HTTP status, count in a metric or show to a user. For those, a custom exception such as OrderNotFoundException, carrying the order ID in a field and mapped by a @RestControllerAdvice, is clearer than an IllegalStateException with a message to parse. A useful rule is: standard exceptions for broken contracts, custom ones for meaningful domain outcomes, and return types for outcomes callers are expected to handle routinely.

7Follow-up questions

Should we catch IllegalArgumentException in calling code?

Usually not. It signals a bug in the caller, so the fix is to pass a valid value. An exception is parsing user input with a library method such as Integer.parseInt, whose NumberFormatException is a subclass of IllegalArgumentException; there, catching it to report invalid input is reasonable, although validating first is often cleaner.

Is NoSuchElementException also one of these?

Yes. It is thrown when we ask for an element that does not exist, for example iterator.next() past the end or Optional.get() and orElseThrow() on an empty Optional. It belongs to the same family of standard unchecked exceptions in java.util.

Why does ConcurrentModificationException happen in a single thread?

Because it is triggered by any structural change to the collection during iteration that does not go through the iterator. The iterator keeps a count of modifications and checks it on each call to next(). Removing an element directly from the list inside a for-each loop changes that count, so the next call to next() throws.

8Conclusion

In this answer, we went through the common standard unchecked exceptions: IllegalArgumentException for an invalid argument value, IllegalStateException when the object's state does not allow the call, UnsupportedOperationException for operations that are never supported, as with List.of(...).add(...), IndexOutOfBoundsException for out-of-range indexes, as thrown by Objects.checkIndex, ConcurrentModificationException from fail-fast iterators, and ArithmeticException for integer division by zero or Math.addExact overflow. Reusing them makes an API familiar, while domain errors deserve their own custom exceptions.

What to say in the interviewAbout 90 seconds aloud

Open with

I would throw IllegalArgumentException when the caller passes a value I cannot accept, like a negative quantity or a percentage over 100, with a message that names the rule and the actual value.

Then, if they want more

IllegalStateException is for when the arguments are fine but the object is in the wrong state, like writing to a closed writer or changing an order that has already shipped. The quick test is: would a different argument fix it, or would the same call work in a different state?

UnsupportedOperationException means the operation is never supported by this object, for example add on a List.of list, or a read-only implementation of a general interface. IndexOutOfBoundsException is for an index outside zero to size minus one, and I would use Objects.checkIndex rather than writing that check myself.

ConcurrentModificationException is thrown by fail-fast iterators when a collection is modified during iteration other than through the iterator, often in a single thread, and I fix that with iterator.remove or removeIf rather than throwing it myself. ArithmeticException is integer division by zero, or overflow from Math.addExact and the other exact methods.

Reusing these makes my API familiar, because everyone knows what they mean. For domain situations like order not found or payment declined, I would define custom exceptions with structured fields, so handlers can map them to proper responses.

About this answer

Last updated
12 November 2026
Checked
Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
Where the question comes from
Written by Scrivio for practice. It is not taken from an interview.
Report an issue with this answer

Copy the line below and send it to the author with what you found. It carries the address of this page.

Issue with "Name common standard unchecked exceptions in the JDK (IllegalArgumentException...": https://scrivio-interview-library.netlify.app/java/exceptions/d3fb4fd6a0/