Java : StackOverflowError with Examples
StackOverflowError (Java SE 21 & JDK 21) with Examples.
You will find code examples on most StackOverflowError methods.
Summary
class Sample {
void recursion() {
System.out.println("Recursion!");
recursion();
}
}
final var sample = new Sample();
try {
sample.recursion();
} catch (StackOverflowError e) {
System.out.println(e);
}
// Result
// ↓
//Recursion!
//Recursion!
//Recursion!
// ・
// ・
// ・
//java.lang.StackOverflowError
Constructors
StackOverflowError ()
final var e = new StackOverflowError();
System.out.println(e); // java.lang.StackOverflowError: abcd
StackOverflowError (String s)
final var e = new StackOverflowError("abcd");
System.out.println(e); // java.lang.StackOverflowError: abcd
System.out.println(e.getMessage()); // abcd
Methods declared in Throwable
addSuppressed, fillInStackTrace, getCause, getLocalizedMessage, getMessage, getStackTrace, getSuppressed, initCause, printStackTrace, printStackTrace, printStackTrace, setStackTrace, toString
Please see the link below.
Related posts
- API Examples
- Error
- Exception
- RuntimeException
- ArithmeticException
- ArrayIndexOutOfBoundsException
- ArrayStoreException
- CancellationException
- ClassCastException
- ConcurrentModificationException
- DateTimeException
- DateTimeParseException
- IllegalArgumentException
- IllegalStateException
- IndexOutOfBoundsException
- NoSuchElementException
- NullPointerException
- PatternSyntaxException
- StringIndexOutOfBoundsException
- UnsupportedOperationException
- Throwable