Java : UnsupportedOperationException with Examples
UnsupportedOperationException (Java SE 17 & JDK 17) API Examples.
You will find code examples on most UnsupportedOperationException methods.
Summary
// List.of returns an unmodifiable list.
final var list = List.of("aaa", "bbb", "ccc");
System.out.println(list); // [aaa, bbb, ccc]
System.out.println(list.get(0)); // aaa
try {
list.add("ddd");
} catch (UnsupportedOperationException e) {
System.out.println("UnsupportedOperationException!");
}
// Result
// ↓
//UnsupportedOperationException!
Constructors
UnsupportedOperationException ()
final var e = new UnsupportedOperationException();
System.out.println(e); // java.lang.UnsupportedOperationException
UnsupportedOperationException (String message)
final var e = new UnsupportedOperationException("abcd");
System.out.println(e); // java.lang.UnsupportedOperationException: abcd
System.out.println(e.getMessage()); // abcd
UnsupportedOperationException (String message, Throwable cause)
final var cause = new IllegalStateException("XYZ");
final var e = new UnsupportedOperationException("abcd", cause);
System.out.println(e); // java.lang.UnsupportedOperationException: abcd
System.out.println(e.getMessage()); // abcd
System.out.println(e.getCause()); // java.lang.IllegalStateException: XYZ
System.out.println(e.getCause().getMessage()); // XYZ
UnsupportedOperationException (Throwable cause)
final var cause = new IllegalStateException("XYZ");
final var e = new UnsupportedOperationException(cause);
System.out.println(e); // java.lang.UnsupportedOperationException: java.lang.IllegalStateException: XYZ
System.out.println(e.getMessage()); // java.lang.IllegalStateException: XYZ
System.out.println(e.getCause()); // java.lang.IllegalStateException: XYZ
System.out.println(e.getCause().getMessage()); // XYZ
Methods declared in Throwable
addSuppressed, fillInStackTrace, getCause, getLocalizedMessage, getMessage, getStackTrace, getSuppressed, initCause, printStackTrace, printStackTrace, printStackTrace, setStackTrace, toString
Please see the link below.
Related posts
- API Examples
- Error
- Exception
- RuntimeException
- ArithmeticException
- ArrayIndexOutOfBoundsException
- ArrayStoreException
- CancellationException
- ClassCastException
- ConcurrentModificationException
- DateTimeException
- DateTimeParseException
- IllegalArgumentException
- IllegalStateException
- IndexOutOfBoundsException
- NoSuchElementException
- NullPointerException
- PatternSyntaxException
- StringIndexOutOfBoundsException
- Throwable