APIdia Launch Partner
Top Description Fields Constructors Methods
java.lang.reflect

public Class UndeclaredThrowableException

extends RuntimeException
Class Inheritance
Imports
java.io.IOException, .ObjectInputStream, .ObjectOutputStream, .ObjectStreamField, jdk.internal.access.SharedSecrets

Thrown by a method invocation on a proxy instance if its invocation handler's invoke method throws a checked exception (a Throwable that is not assignable to RuntimeException or Error) that is not assignable to any of the exception types declared in the throws clause of the method that was invoked on the proxy instance and dispatched to the invocation handler.

An UndeclaredThrowableException instance contains the undeclared checked exception that was thrown by the invocation handler, and it can be retrieved with the getUndeclaredThrowable() method. UndeclaredThrowableException extends RuntimeException, so it is an unchecked exception that wraps a checked exception.

Author
Peter Jones
Since
1.3
See Also
InvocationHandler

Field Summary

Modifier and TypeField and Description
private static final ObjectStreamField[]
serialPersistentFields

Serializable fields for UndeclaredThrowableException.

pack-priv static final long

Constructor Summary

AccessConstructor and Description
public
UndeclaredThrowableException(Throwable
the undeclared checked exception that was thrown, may be null
undeclaredThrowable
)

Constructs an UndeclaredThrowableException with the specified Throwable.

public
UndeclaredThrowableException(Throwable
the undeclared checked exception that was thrown, may be null
undeclaredThrowable
,
String
the detail message, may be null
s
)

Constructs an UndeclaredThrowableException with the specified Throwable and a detail message.

Method Summary

Modifier and TypeMethod and Description
public Throwable

Returns:

the undeclared checked exception that was thrown
getUndeclaredThrowable
()

Returns the Throwable instance wrapped in this UndeclaredThrowableException, which may be null.

private void
readObject(ObjectInputStream
the ObjectInputStream from which data is read
s
)

Hides java.lang.Throwable.readObject.

Reconstitutes the UndeclaredThrowableException instance from a stream and initialize the cause properly when deserializing from an older version.

private void
writeObject(ObjectOutputStream
the ObjectOutputStream to which data is written
out
)

Hides java.lang.Throwable.writeObject.

To maintain compatibility with older implementation, write a serial "ex" field with the cause as the value.

Field Detail

serialPersistentFieldsback to summary
private static final ObjectStreamField[] serialPersistentFields

Serializable fields for UndeclaredThrowableException.

Annotations
@Serial
Serial Fields:
undeclaredThrowable:Throwable
the undeclared exception
serialVersionUIDback to summary
pack-priv static final long serialVersionUID

Hides java.lang.RuntimeException.serialVersionUID.

Annotations
@Serial

Constructor Detail

UndeclaredThrowableExceptionback to summary
public UndeclaredThrowableException(Throwable undeclaredThrowable)

Constructs an UndeclaredThrowableException with the specified Throwable.

Parameters
undeclaredThrowable:Throwable

the undeclared checked exception that was thrown, may be null

UndeclaredThrowableExceptionback to summary
public UndeclaredThrowableException(Throwable undeclaredThrowable, String s)

Constructs an UndeclaredThrowableException with the specified Throwable and a detail message.

Parameters
undeclaredThrowable:Throwable

the undeclared checked exception that was thrown, may be null

s:String

the detail message, may be null

Method Detail

getUndeclaredThrowableback to summary
public Throwable getUndeclaredThrowable()

Returns the Throwable instance wrapped in this UndeclaredThrowableException, which may be null.

API Note

This method predates the general-purpose exception chaining facility. The Throwable#getCause() method is now the preferred means of obtaining this information.

Returns:Throwable

the undeclared checked exception that was thrown

readObjectback to summary
private void readObject(ObjectInputStream s) throws IOException, ClassNotFoundException

Hides java.lang.Throwable.readObject.

Reconstitutes the UndeclaredThrowableException instance from a stream and initialize the cause properly when deserializing from an older version.

Parameters
s:ObjectInputStream

the ObjectInputStream from which data is read

Annotations
@Serial
Exceptions
IOException:
if an I/O error occurs
ClassNotFoundException:
if a serialized class cannot be loaded
writeObjectback to summary
private void writeObject(ObjectOutputStream out) throws IOException

Hides java.lang.Throwable.writeObject.

To maintain compatibility with older implementation, write a serial "ex" field with the cause as the value.

Parameters
out:ObjectOutputStream

the ObjectOutputStream to which data is written

Annotations
@Serial
Exceptions
IOException:
if an I/O error occurs