public class ClosedIORuntimeException extends IORuntimeException
ClosedIORuntimeException is thrown to indicate that an I/O operation has been
attempted on a closed I/O resource, such as a file or network connection. This exception
is used when the state of the resource renders it unsuitable for the requested operation.
This exception is a specialized subclass of IORuntimeException, which is an unchecked
wrapper for the standard checked IOException. ClosedIORuntimeException
specifically targets scenarios where the illegal operation is due to the underlying resource
being closed.
ClosedIORuntimeException is used to report a runtime I/O exception that arises
from the closed state of the resource, without requiring the method to declare it in its
throws clause. This is useful in situations where reporting the exception is necessary
but forcing the calling code to catch it is not desired.
Here's an example of how ClosedIORuntimeException might be used:
public void writeToStream(OutputStream stream, byte[] data) {
try {
stream.write(data);
} catch (IOException e) {
if (stream.isClosed())
throw new ClosedIORuntimeException("Stream is closed", e);
throw new IORuntimeException("Failed to write to stream", e);
}
}
| Constructor and Description |
|---|
ClosedIORuntimeException(String message)
Constructs a
ClosedIORuntimeException with the specified detail message. |
ClosedIORuntimeException(String message,
Throwable thrown)
Constructs a
ClosedIORuntimeException with the specified detail message and cause. |
newIORuntimeExceptionaddSuppressed, fillInStackTrace, getCause, getLocalizedMessage, getMessage, getStackTrace, getSuppressed, initCause, printStackTrace, printStackTrace, printStackTrace, setStackTrace, toStringpublic ClosedIORuntimeException(String message)
ClosedIORuntimeException with the specified detail message.
The detail message is intended to provide more information on why the exception was thrown.message - The detail message, which is saved for later retrieval by the Throwable.getMessage() method.public ClosedIORuntimeException(String message, Throwable thrown)
ClosedIORuntimeException with the specified detail message and cause.
Note that the detail message associated with cause is not automatically
incorporated into this exception's detail message.
message - The detail message, which is saved for later retrieval by the Throwable.getMessage() method.thrown - The cause (which is saved for later retrieval by the Throwable.getCause() method).
A null value is permitted and indicates that the cause is nonexistent or unknown.Copyright © 2024. All rights reserved.