Java : BufferUnderflowException 示例

Java 中的 BufferUnderflowException (Java SE 23 & JDK 23) 及其示例。
您将找到大多数 BufferUnderflowException 方法的代码示例。

注解 :

  • 本文可能使用了翻译软件以方便阅读。 另请查看英文原文

简介

当相对获取操作达到源缓冲区的限制时抛出未经检查的异常。 (机器翻译)

Class diagram

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 ()

构造此类的一个实例。 (机器翻译)

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

请参阅下面的链接。


相关文章

To top of page