public class InterruptedRuntimeException extends IllegalStateException
This unchecked exception serves as an alternative to the checked InterruptedException.
Generally, it is recommended to use InterruptedException to handle interruptions.
However, in scenarios where handling checked exceptions is not feasible or desirable, this
class can be used to represent thread interruption without being subject to the checked
exception requirements.
When converting from InterruptedException to InterruptedRuntimeException, it is
important to preserve the interrupt status by calling Thread.interrupt() before
throwing this exception.
Example usage:
try {
// Code that may throw InterruptedException
} catch (InterruptedException e) {
Thread.currentThread().interrupt(); // Preserve interrupt status
throw new InterruptedRuntimeException("Thread was interrupted", e);
}
| Constructor and Description |
|---|
InterruptedRuntimeException()
Constructs an
InterruptedRuntimeException with no detail message or cause. |
InterruptedRuntimeException(String message)
Constructs an
InterruptedRuntimeException with the specified detail message. |
InterruptedRuntimeException(String message,
Throwable cause)
Constructs an
InterruptedRuntimeException with the specified detail message and cause. |
InterruptedRuntimeException(Throwable cause)
Constructs an
InterruptedRuntimeException with the specified cause and a detail
message of (cause == null ? null : cause.toString()) (which typically contains
the class and detail message of cause). |
addSuppressed, fillInStackTrace, getCause, getLocalizedMessage, getMessage, getStackTrace, getSuppressed, initCause, printStackTrace, printStackTrace, printStackTrace, setStackTrace, toStringpublic InterruptedRuntimeException()
InterruptedRuntimeException with no detail message or cause.public InterruptedRuntimeException(String message)
InterruptedRuntimeException with the specified detail message.message - the detail message.public InterruptedRuntimeException(String message, Throwable cause)
InterruptedRuntimeException 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.cause - 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.public InterruptedRuntimeException(Throwable cause)
InterruptedRuntimeException with the specified cause and a detail
message of (cause == null ? null : cause.toString()) (which typically contains
the class and detail message of cause).cause - 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.