Java : BufferOverflowException con ejemplos

BufferOverflowException (Java SE 23 & JDK 23) en Java con ejemplos.
Encontrará muestras de código para la mayoría de los métodos BufferOverflowException.

Nota :


Summary

Se lanza una excepción no controlada cuando una operación de colocación relativa alcanza el límite del búfer de destino. (Traducción automática)

Class diagram

final var buffer = CharBuffer.allocate(3);
System.out.println(buffer.capacity()); // 3
System.out.println(buffer.position()); // 0

buffer.put('a');
buffer.put('b');
buffer.put('c');

if (buffer.hasArray()) {
    final var array = buffer.array();
    System.out.println(Arrays.toString(array)); // [a, b, c]
}

try {
    buffer.put('d');
} catch (BufferOverflowException e) {
    System.out.println("BufferOverflowException!");
}

// Result
// ↓
//BufferOverflowException!

Constructors

BufferOverflowException ()

Construye una instancia de esta clase. (Traducción automática)

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

Methods declared in Throwable

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

Consulte el siguiente enlace.


Related posts

To top of page