Java : ReadOnlyBufferException with Examples

ReadOnlyBufferException (Java SE 23 & JDK 23) in Java with Examples.
You will find code samples for most of the ReadOnlyBufferException methods.


Summary

Unchecked exception thrown when a content-mutation method such as put or compact is invoked upon a read-only buffer.

Class diagram

final var buffer = IntBuffer.allocate(5).asReadOnlyBuffer();
System.out.println(buffer.isReadOnly()); // true

try {
    buffer.put(10);
} catch (ReadOnlyBufferException e) {
    System.out.println("ReadOnlyBufferException!");
}

// Result
// ↓
//ReadOnlyBufferException!

Constructors

ReadOnlyBufferException ()

Constructs an instance of this class.

final var e = new ReadOnlyBufferException();
System.out.println(e); // java.nio.ReadOnlyBufferException

Methods declared in Throwable

addSuppressed, fillInStackTrace, getCause, getLocalizedMessage, getMessage, getStackTrace, getSuppressed, initCause, printStackTrace, printStackTrace, printStackTrace, setStackTrace, toString

Please see the link below.


Related posts

To top of page