Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to find cause of exception if type is Throwable

Give this method here:

public SomeClass(Throwable stackTrace) {
    super();
    this.stackTrace = stackTrace;
}

How can I find out what class type stacktrace originally was before being passed in?

like image 324
Zombies Avatar asked Jul 28 '11 14:07

Zombies


People also ask

Does throwable catch exception?

If you use Throwable in a catch clause, it will not only catch all exceptions; it will also catch all errors. Errors are thrown by the JVM to indicate serious problems that are not intended to be handled by an application. Typical examples for that are the OutOfMemoryError or the StackOverflowError.

Is exception instance of throwable?

A throwable object is an instance of class Throwable (or one of its subclasses). Exception and Error are two subclasses of class Throwable , and each has many subclasses itself.

Is exception subclass of throwable?

Throwable has two direct subclasses - Exception and Error. The Exception class is used for exception conditions that the application may need to handle. Examples of exceptions include IllegalArgumentException , ClassNotFoundException and NullPointerException .

Does throwable extend exception?

No, it is nor mandatory to extend the exception class to create custom exceptions, you can create them just by extending Throwable class, the super class of all exceptions.


1 Answers

stacktrace.getClass().getName()

or

stacktrace instanceof CLASS_YOU_WANT_TO_TRY
like image 196
nfechner Avatar answered Oct 16 '22 08:10

nfechner