Java : BufferUnderflowException with Examples
BufferUnderflowException (Java SE 23 & JDK 23) in Java with Examples.
You will find code samples for most of the BufferUnderflowException methods.
Summary
Unchecked exception thrown when a relative get operation reaches the source buffer's limit.
final char[] array = {'a', 'b', 'c'};
final var buffer = CharBuffer.wrap(array);
{
final var dst = new char[3];
final var ret = buffer.get(dst);
System.out.println(ret.position()); // 3
System.out.println(Arrays.toString(dst)); // [a, b, c]
}
try {
final var dst = new char[1];
var _ = buffer.get(dst);
} catch (BufferUnderflowException e) {
System.out.println("BufferUnderflowException!");
}
// Result
// ↓
//BufferUnderflowException!
Constructors
BufferUnderflowException ()
Constructs an instance of this class.
final var e = new BufferUnderflowException();
System.out.println(e); // java.nio.BufferUnderflowException
Methods declared in Throwable
addSuppressed, fillInStackTrace, getCause, getLocalizedMessage, getMessage, getStackTrace, getSuppressed, initCause, printStackTrace, printStackTrace, printStackTrace, setStackTrace, toString
Please see the link below.