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?
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.
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.
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 .
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.
stacktrace.getClass().getName()
or
stacktrace instanceof CLASS_YOU_WANT_TO_TRY
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With