This exception is thrown by the AccessController to indicate
that a requested access (to a critical system resource such as the
file system or the network) is denied.
This class was deprecated
in API level 33.
This class is deprecated and subject to removal in a future
version of Java SE. It has been replaced by java.security.Policy
and related classes since 1.2.
This exception is thrown when a call to Context.startActivity or
one of its variants fails because an Activity can not be found to execute
the given Intent.
This class was deprecated
in API level 37.
The Rubidium (Rb) Measurement APIs, including those in
android.adservices.measurement, are being deprecated. There are no direct replacement APIs
for the Measurement APIs. Developers currently using these APIs should cease integration, as
calls to these APIs will be rejected in upcoming Android releases as part of a soft removal
process. Please refer to the official Privacy Sandbox developer documentation and
announcements for more details on this deprecation and the future roadmap of Privacy Sandbox
on Android: https://privacysandbox.com/news/update-on-plans-for-privacy-sandbox-technologies/
Thrown to indicate that a program has attempted to access an element of
an annotation whose type has changed after the annotation was compiled
(or serialized).
Thrown to indicate that a preferences operation could not complete because
of a failure in the backing store, or a failure to contact the backing
store.
Thrown to indicate that an invokedynamic instruction or a dynamic
constant failed to resolve its bootstrap method and arguments,
or for invokedynamic instruction the bootstrap method has failed to
provide a
call site with a
target
of the correct method type,
or for a dynamic constant the bootstrap method has failed to provide a
constant value of the required type.
CameraAccessException is thrown if a camera device could not
be queried or opened by the CameraManager, or if the connection to an
opened CameraDevice is no longer valid.
Thrown when the Java Virtual Machine attempts to read a class
file and determines that the file is malformed or otherwise cannot
be interpreted as a class file.
Thrown to indicate that the clone method in class
Object has been called to clone an object, but that
the object's class does not implement the Cloneable
interface.
Checked exception thrown when an attempt is made to invoke or complete an
I/O operation upon channel that is closed, or at least closed to that
operation.
DOM operations only raise exceptions in "exceptional" circumstances, i.e.,
when an operation is impossible to perform (either for logical reasons,
because data is lost, or because the implementation has become unstable).
An exception thrown as a DataTruncation exception
(on writes) or reported as a
DataTruncation warning (on reads)
when a data values is unexpectedly truncated for reasons other than its having
execeeded MaxFieldSize.
The GeneralSecurityException class is a generic
security exception class that provides type safety for all the
security-related exception classes that extend from it.
Thrown when a syntactically malformed signature attribute is
encountered by a reflective method that needs to interpret the
generic signature information for a type, method or constructor.
An IllegalAccessException is thrown when an application tries
to reflectively create an instance (other than an array),
set or get a field, or invoke a method, but the currently
executing method does not have access to the definition of
the specified class, field, method or constructor.
Unchecked exception thrown when the precision is a negative value other than
-1, the conversion does not support a precision, or the value is
otherwise unsupported.
Thrown to indicate that a thread has attempted to wait on an
object's monitor or to notify other threads waiting on an object's
monitor without owning the specified monitor.
Unchecked exception thrown when an attempt is made to register a channel
with a selector that was not created by the provider that created the
channel.
Thrown to indicate that a program has attempted to access an element of
an annotation interface that was added to the annotation interface definition
after the annotation was compiled (or serialized).
Thrown by a Scanner to indicate that the token
retrieved does not match the pattern for the expected type, or
that the token is out of range for the expected type.
Thrown when an application tries to create an instance of a class
using the newInstance method in class
Class, but the specified class object cannot be
instantiated.
Unchecked exception thrown when path string cannot be converted into a
Path because the path string contains invalid characters, or
the path string is invalid for other file system specific reasons.
Thrown to indicate that an operation could not complete because
the input did not conform to the appropriate XML document type
for a collection of preferences, as per the Preferences
specification.
Thrown to indicate that an operation could not complete because
the input did not conform to the appropriate XML document type
for a collection of properties, as per the Properties
specification.
This class was deprecated
in API level 37.
The ODP APIs are deprecated and will not be supported in future Android releases.
There is no direct replacement API available. Developers currently integrated with these APIs
must cease further integration efforts. For comprehensive details regarding this deprecation and
the future roadmap of Privacy Sandbox on Android, please consult the official Privacy Sandbox
developer documentation and announcements:
https://privacysandbox.google.com
This class was deprecated
in API level 33.
This class is deprecated and subject to removal in a future
version of Java SE. It has been replaced by java.security.Policy
and related classes since 1.2.
Subclasses of LinkageError indicate that a class has
some dependency on another class; however, the latter class has
incompatibly changed after the compilation of the former class.
Checked exception thrown when an input byte sequence is not legal for given
charset, or an input character sequence is not a legal sixteen-bit Unicode
sequence.
Thrown when the
java.lang.reflect package attempts to read method parameters from
a class file and determines that one or more parameters are
malformed.
Exception thrown when an operation on a MediaCas object is attempted
and hardware resources are not sufficient to allocate, due to client's lower priority.
Thrown when the device requires DRM provisioning but the provisioning attempt has
failed due to a network error (Internet reachability, timeout, etc.).
Unchecked exception thrown when there is a format specifier which does not
have a corresponding argument or if an argument index refers to an argument
that does not exist.
Thrown if the Java Virtual Machine or a ClassLoader instance
tries to load in the definition of a class (as part of a normal method call
or as part of creating a new instance using the new expression)
and no definition of the class could be found.
Thrown if an application tries to call a specified method of a
class (either static or instance), and that class no longer has a
definition of that method.
This class was deprecated
in API level 33.
This class is deprecated and subject to removal in a future
version of Java SE. It has been replaced by java.security.Policy
and related classes since 1.2.
Thrown to indicate that the application has attempted to convert
a string to one of the numeric types, but that the string does not
have the appropriate format.
This class was deprecated
in API level 37.
The ODP APIs are deprecated and will not be supported in future Android releases.
There is no direct replacement API available. Developers currently integrated with these APIs
must cease further integration efforts. For comprehensive details regarding this deprecation and
the future roadmap of Privacy Sandbox on Android, please consult the official Privacy Sandbox
developer documentation and announcements:
https://privacysandbox.google.com
Exception indicating the failure of an object read operation due to
unread primitive data, or the end of data belonging to a serialized
object in the stream.
Thrown when the Java Virtual Machine cannot allocate an object
because it is out of memory, and no more memory could be made
available by the garbage collector.
Unchecked exception thrown when an attempt is made to acquire a lock on a
region of a file that overlaps a region already locked by the same Java
virtual machine, or when another thread is already waiting to lock an
overlapping region of the same file.
A runtime exception for Provider exceptions (such as
misconfiguration errors or unrecoverable internal errors),
which may be subclassed by Providers to
throw specialized, provider-specific runtime errors.
Unchecked exception thrown when an attempt is made to invoke a method on an
object created by one file system provider with a parameter created by a
different file system provider.
This class was deprecated
in API level 31.
Renderscript has been deprecated in API level 31. Please refer to the migration
guide for the proposed alternatives.
This class was deprecated
in API level 31.
Renderscript has been deprecated in API level 31. Please refer to the migration
guide for the proposed alternatives.
This class was deprecated
in API level 31.
Renderscript has been deprecated in API level 31. Please refer to the migration
guide for the proposed alternatives.
This class was deprecated
in API level 31.
Renderscript has been deprecated in API level 31. Please refer to the migration
guide for the proposed alternatives.
The subclass of SQLException thrown in situations where a
previously failed operation might be able to succeed if the application performs
some recovery steps and retries the entire transaction or in the case of a
distributed transaction, the transaction branch.
The subclass of SQLException is thrown in situations where a
previoulsy failed operation might be able to succeed when the operation is
retried without any intervention by application-level functionality.
Unchecked exception thrown when an attempt is made to construct a channel in
a group that is shutdown or the completion handler for an I/O operation
cannot be invoked because the channel group has terminated.
This class was deprecated
in API level 31.
SipManager and associated classes are no longer supported and
should not be used as the basis of future VOIP apps.
The TooManyListenersException Exception is used as part of
the Java Event model to annotate and implement a unicast special case of
a multicast Event Source.
Thrown when an application tries to access a type using a string
representing the type's name, but no definition for the type with
the specified name can be found.
Signals that a malformed string in
modified UTF-8
format has been read in a data
input stream or by any class that implements the data input
interface.
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.
Thrown when the Java Virtual Machine attempts to read a class
file and determines that the major and minor version numbers
in the file are not supported.
Thrown to indicate a problem with time-zone configuration.
The Throwable class is the superclass of all errors and
exceptions in the Java language. Only objects that are instances of this
class (or one of its subclasses) are thrown by the Java Virtual Machine or
can be thrown by the Java throw statement. Similarly, only
this class or one of its subclasses can be the argument type in a
catch clause.
For the purposes of compile-time checking of exceptions, Throwable and any subclass of Throwable that is not also a
subclass of either RuntimeException or Error are
regarded as checked exceptions.
Instances of two subclasses, Error and
Exception, are conventionally used to indicate
that exceptional situations have occurred. Typically, these instances
are freshly created in the context of the exceptional situation so
as to include relevant information (such as stack trace data).
A throwable contains a snapshot of the execution stack of its
thread at the time it was created. It can also contain a message
string that gives more information about the error. Over time, a
throwable can suppress other
throwables from being propagated. Finally, the throwable can also
contain a cause: another throwable that caused this
throwable to be constructed. The recording of this causal information
is referred to as the chained exception facility, as the
cause can, itself, have a cause, and so on, leading to a "chain" of
exceptions, each caused by another.
One reason that a throwable may have a cause is that the class that
throws it is built atop a lower layered abstraction, and an operation on
the upper layer fails due to a failure in the lower layer. It would be bad
design to let the throwable thrown by the lower layer propagate outward, as
it is generally unrelated to the abstraction provided by the upper layer.
Further, doing so would tie the API of the upper layer to the details of
its implementation, assuming the lower layer's exception was a checked
exception. Throwing a "wrapped exception" (i.e., an exception containing a
cause) allows the upper layer to communicate the details of the failure to
its caller without incurring either of these shortcomings. It preserves
the flexibility to change the implementation of the upper layer without
changing its API (in particular, the set of exceptions thrown by its
methods).
A second reason that a throwable may have a cause is that the method
that throws it must conform to a general-purpose interface that does not
permit the method to throw the cause directly. For example, suppose
a persistent collection conforms to the Collection interface, and that its persistence is implemented atop
java.io. Suppose the internals of the add method
can throw an IOException. The implementation
can communicate the details of the IOException to its caller
while conforming to the Collection interface by wrapping the
IOException in an appropriate unchecked exception. (The
specification for the persistent collection should indicate that it is
capable of throwing such exceptions.)
A cause can be associated with a throwable in two ways: via a
constructor that takes the cause as an argument, or via the
initCause(Throwable) method. New throwable classes that
wish to allow causes to be associated with them should provide constructors
that take a cause and delegate (perhaps indirectly) to one of the
Throwable constructors that takes a cause.
Because the initCause method is public, it allows a cause to be
associated with any throwable, even a "legacy throwable" whose
implementation predates the addition of the exception chaining mechanism to
Throwable.
By convention, class Throwable and its subclasses have two
constructors, one that takes no arguments and one that takes a
String argument that can be used to produce a detail message.
Further, those subclasses that might likely have a cause associated with
them should have two more constructors, one that takes a
Throwable (the cause), and one that takes a
String (the detail message) and a Throwable (the
cause).
Constructs a new throwable with the specified cause and a detail
message of (cause==null ? null : cause.toString()) (which
typically contains the class and detail message of cause).
Returns an array containing all of the exceptions that were
suppressed, typically by the try-with-resources
statement, in order to deliver this exception.
Causes the current thread to wait until it is awakened, typically
by being notified or interrupted, or until a
certain amount of real time has elapsed.
Causes the current thread to wait until it is awakened, typically
by being notified or interrupted, or until a
certain amount of real time has elapsed.
Constructs a new throwable with null as its detail message.
The cause is not initialized, and may subsequently be initialized by a
call to initCause(Throwable).
The fillInStackTrace() method is called to initialize
the stack trace data in the newly created throwable.
Constructs a new throwable with the specified detail message. The
cause is not initialized, and may subsequently be initialized by
a call to initCause(Throwable).
The fillInStackTrace() method is called to initialize
the stack trace data in the newly created throwable.
Parameters
message
String: the detail message. The detail message is saved for
later retrieval by the getMessage() method.
Constructs a new throwable with the specified detail message and
cause.
Note that the detail message associated with
cause is not automatically incorporated in
this throwable's detail message.
The fillInStackTrace() method is called to initialize
the stack trace data in the newly created throwable.
Parameters
message
String: the detail message (which is saved for later retrieval
by the getMessage() method).
cause
Throwable: the cause (which is saved for later retrieval by the
getCause() method). (A null value is
permitted, and indicates that the cause is nonexistent or
unknown.)
Constructs a new throwable with the specified cause and a detail
message of (cause==null ? null : cause.toString()) (which
typically contains the class and detail message of cause).
This constructor is useful for throwables that are little more than
wrappers for other throwables (for example, PrivilegedActionException).
The fillInStackTrace() method is called to initialize
the stack trace data in the newly created throwable.
Parameters
cause
Throwable: the cause (which is saved for later retrieval by the
getCause() method). (A null value is
permitted, and indicates that the cause is nonexistent or
unknown.)
Constructs a new throwable with the specified detail message,
cause, suppression enabled or
disabled, and writable stack trace enabled or disabled. If
suppression is disabled, getSuppressed() for this object
will return a zero-length array and calls to addSuppressed(Throwable) that would otherwise append an exception to the
suppressed list will have no effect. If the writable stack
trace is false, this constructor will not call fillInStackTrace(), a null will be written to the
stackTrace field, and subsequent calls to fillInStackTrace and setStackTrace(StackTraceElement[]) will not set the stack
trace. If the writable stack trace is false, getStackTrace() will return a zero length array.
Note that the other constructors of Throwable treat
suppression as being enabled and the stack trace as being
writable. Subclasses of Throwable should document any
conditions under which suppression is disabled and document
conditions under which the stack trace is not writable.
Disabling of suppression should only occur in exceptional
circumstances where special requirements exist, such as a
virtual machine reusing exception objects under low-memory
situations. Circumstances where a given exception object is
repeatedly caught and rethrown, such as to implement control
flow between two sub-systems, is another situation where
immutable throwable objects would be appropriate.
Parameters
message
String: the detail message.
cause
Throwable: the cause. (A null value is permitted,
and indicates that the cause is nonexistent or unknown.)
enableSuppression
boolean: whether or not suppression is enabled or disabled
writableStackTrace
boolean: whether or not the stack trace should be
writable
public final void addSuppressed (Throwable exception)
Appends the specified exception to the exceptions that were
suppressed in order to deliver this exception. This method is
thread-safe and typically called (automatically and implicitly)
by the try-with-resources statement.
The suppression behavior is enabled unless disabled
via
a constructor. When suppression is disabled, this method does
nothing other than to validate its argument.
Note that when one exception causes another exception, the first
exception is usually caught and then the second exception is
thrown in response. In other words, there is a causal
connection between the two exceptions.
In contrast, there are situations where two independent
exceptions can be thrown in sibling code blocks, in particular
in the try block of a try-with-resources
statement and the compiler-generated finally block
which closes the resource.
In these situations, only one of the thrown exceptions can be
propagated. In the try-with-resources statement, when
there are two such exceptions, the exception originating from
the try block is propagated and the exception from the
finally block is added to the list of exceptions
suppressed by the exception from the try block. As an
exception unwinds the stack, it can accumulate multiple
suppressed exceptions.
An exception may have suppressed exceptions while also being
caused by another exception. Whether or not an exception has a
cause is semantically known at the time of its creation, unlike
whether or not an exception will suppress other exceptions
which is typically only determined after an exception is
thrown.
Note that programmer written code is also able to take
advantage of calling this method in situations where there are
multiple sibling exceptions and only one can be propagated.
Parameters
exception
Throwable: the exception to be added to the list of
suppressed exceptions
Fills in the execution stack trace. This method records within this
Throwable object information about the current state of
the stack frames for the current thread.
If the stack trace of this Throwableis not
writable, calling this method has no effect.
Returns the cause of this throwable or null if the
cause is nonexistent or unknown. (The cause is the throwable that
caused this throwable to get thrown.)
This implementation returns the cause that was supplied via one of
the constructors requiring a Throwable, or that was set after
creation with the initCause(Throwable) method. While it is
typically unnecessary to override this method, a subclass can override
it to return a cause set by some other means. This is appropriate for
a "legacy chained throwable" that predates the addition of chained
exceptions to Throwable. Note that it is not
necessary to override any of the PrintStackTrace methods,
all of which invoke the getCause method to determine the
cause of a throwable.
Creates a localized description of this throwable.
Subclasses may override this method in order to produce a
locale-specific message. For subclasses that do not override this
method, the default implementation returns the same result as
getMessage().
Provides programmatic access to the stack trace information printed by
printStackTrace(). Returns an array of stack trace elements,
each representing one stack frame. The zeroth element of the array
(assuming the array's length is non-zero) represents the top of the
stack, which is the last method invocation in the sequence. Typically,
this is the point at which this throwable was created and thrown.
The last element of the array (assuming the array's length is non-zero)
represents the bottom of the stack, which is the first method invocation
in the sequence.
Some virtual machines may, under some circumstances, omit one
or more stack frames from the stack trace. In the extreme case,
a virtual machine that has no stack trace information concerning
this throwable is permitted to return a zero-length array from this
method. Generally speaking, the array returned by this method will
contain one element for every frame that would be printed by
printStackTrace. Writes to the returned array do not
affect future calls to this method.
Returns an array containing all of the exceptions that were
suppressed, typically by the try-with-resources
statement, in order to deliver this exception.
If no exceptions were suppressed or suppression is
disabled, an empty array is returned. This method is
thread-safe. Writes to the returned array do not affect future
calls to this method.
Initializes the cause of this throwable to the specified value.
(The cause is the throwable that caused this throwable to get thrown.)
This method can be called at most once. It is generally called from
within the constructor, or immediately after creating the
throwable. If this throwable was created
with Throwable(Throwable) or
Throwable(String,Throwable), this method cannot be called
even once.
An example of using this method on a legacy throwable type
without other support for setting the cause is:
Throwable: the cause (which is saved for later retrieval by the
getCause() method). (A null value is
permitted, and indicates that the cause is nonexistent or
unknown.)
Prints this throwable and its backtrace to the
standard error stream. This method prints a stack trace for this
Throwable object on the error output stream that is
the value of the field System.err. The first line of
output contains the result of the toString() method for
this object. Remaining lines represent data previously recorded by
the method fillInStackTrace(). The format of this
information depends on the implementation, but the following
example may be regarded as typical:
java.lang.NullPointerException
at MyClass.mash(MyClass.java:9)
at MyClass.crunch(MyClass.java:6)
at MyClass.main(MyClass.java:3)
This example was produced by running the program:
class MyClass {
public static void main(String[] args) {
crunch(null);
}
static void crunch(int[] a) {
mash(a);
}
static void mash(int[] b) {
System.out.println(b[0]);
}
}
The backtrace for a throwable with an initialized, non-null cause
should generally include the backtrace for the cause. The format
of this information depends on the implementation, but the following
example may be regarded as typical:
HighLevelException: MidLevelException: LowLevelException
at Junk.a(Junk.java:13)
at Junk.main(Junk.java:4)
Caused by: MidLevelException: LowLevelException
at Junk.c(Junk.java:23)
at Junk.b(Junk.java:17)
at Junk.a(Junk.java:11)
... 1 more
Caused by: LowLevelException
at Junk.e(Junk.java:30)
at Junk.d(Junk.java:27)
at Junk.c(Junk.java:21)
... 3 more
Note the presence of lines containing the characters "...".
These lines indicate that the remainder of the stack trace for this
exception matches the indicated number of frames from the bottom of the
stack trace of the exception that was caused by this exception (the
"enclosing" exception). This shorthand can greatly reduce the length
of the output in the common case where a wrapped exception is thrown
from same method as the "causative exception" is caught. The above
example was produced by running the program:
As of release 7, the platform supports the notion of
suppressed exceptions (in conjunction with the try-with-resources statement). Any exceptions that were
suppressed in order to deliver an exception are printed out
beneath the stack trace. The format of this information
depends on the implementation, but the following example may be
regarded as typical:
Exception in thread "main" java.lang.Exception: Something happened
at Foo.bar(Foo.java:10)
at Foo.main(Foo.java:5)
Suppressed: Resource$CloseFailException: Resource ID = 0
at Resource.close(Resource.java:26)
at Foo.bar(Foo.java:9)
... 1 more
Note that the "... n more" notation is used on suppressed exceptions
just as it is used on causes. Unlike causes, suppressed exceptions are
indented beyond their "containing exceptions."
An exception can have both a cause and one or more suppressed
exceptions:
Exception in thread "main" java.lang.Exception: Main block
at Foo3.main(Foo3.java:7)
Suppressed: Resource$CloseFailException: Resource ID = 2
at Resource.close(Resource.java:26)
at Foo3.main(Foo3.java:5)
Suppressed: Resource$CloseFailException: Resource ID = 1
at Resource.close(Resource.java:26)
at Foo3.main(Foo3.java:5)
Caused by: java.lang.Exception: I did it
at Foo3.main(Foo3.java:8)
Likewise, a suppressed exception can have a cause:
Exception in thread "main" java.lang.Exception: Main block
at Foo4.main(Foo4.java:6)
Suppressed: Resource2$CloseFailException: Resource ID = 1
at Resource2.close(Resource2.java:20)
at Foo4.main(Foo4.java:5)
Caused by: java.lang.Exception: Rats, you caught me
at Resource2$CloseFailException.<init>(Resource2.java:45)
... 2 more
Sets the stack trace elements that will be returned by
getStackTrace() and printed by printStackTrace()
and related methods.
This method, which is designed for use by RPC frameworks and other
advanced systems, allows the client to override the default
stack trace that is either generated by fillInStackTrace()
when a throwable is constructed or deserialized when a throwable is
read from a serialization stream.
If the stack trace of this Throwableis not
writable, calling this method has no effect other than
validating its argument.
Parameters
stackTrace
StackTraceElement: the stack trace elements to be associated with
this Throwable. The specified array is copied by this
call; changes in the specified array after the method invocation
returns will have no affect on this Throwable's stack
trace.
Content and code samples on this page are subject to the licenses described in the Content License. Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
Last updated 2026-04-16 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2026-04-16 UTC."],[],[]]