StackOverflowError is a unchecked exception under Error Class in Throwable hierarchy, which may occur when the stack contains too many nested methods. The best example is an uncontrolled recursion function.
Let's see how to create our own StackOverflow exception :
Just create a function that calls itself:
StackOveflowExample.javapackage org.code2care.stackoverflow;
public class StackOveflowExample {
public static void main(String[] args) {
stackOveflowMethod();
}
public static void stackOveflowMethod() {
stackOveflowMethod(); //recursion
}
}
exception in the thread "main" java.lang.StackOveflowError
at org.code2care.stackoverflow.StackOveflowExample.stackOveflowMethod(StackOveflowExample.java:13)
at org.code2care.stackoverflow.StackOveflowExample.stackOveflowMethod(StackOveflowExample.java:13)
at org.code2care.stackoverflow.StackOveflowExample.stackOveflowMethod(StackOveflowExample.java:13)
....
....
HashTags : #Exceptions #Error #Java #StackOverflow
More Posts related to Java,
- Deep Dive into Java 8 Predicate Interface
- Read and Parse XML file using Java DOM Parser [Java Tutorial]
- Java 8 Predicate Functional Interface isEqual() Method Example
- Convert Multidimensional Array toString In Java
- How to read int value using Scanner Class Java
- Spring Boot AI + LLM + Java Code Example
- Write to a File using Java Stream API
- Implementing Bubble Sort Algorithm using Java Program
- How to Fix XmlBeanDefinitionStoreException in Java SpringBoot ApplicationConfig.xml
- YAML Parser using Java Jackson Library Example
- [Fix] java: integer number too large compilation error
- Convert JSON String to Java GSON Object Example
- Read a file using Java 8 Stream
- Java Spring Boot 3 Web Hello World with Gradle in IntelliJ
- Ways Compare Dates in Java Programming with Examples
- Pretty Print JSON String in Java Console Output
- Java JDBC with Join Queries Example
- How to Check For Updates on Windows 11 (Step-by-Step)
- [Fix] java.net.MalformedURLException: unknown protocol
- How to display date and time in GMT Timezone in Java
- Error: LinkageError occurred while loading main class UnsupportedClassVersionError [Eclipse Java]
- How to convert a String to Java 8 Stream of Char?
- RabbitMQ Queue Listener Java Spring Boot Code Example
- 5+ Fibonacci number Series Java Program Examples [ 0 1 1 2 3 ..]
- Handling NullPointerException with Java Predicate
More Posts:
- How to install iTerm2 Mac Terminal Alternative - MacOS
- Setting JAVA_HOME in macOS Big Sur - MacOS
- Fixing Android unknown error 961 while downloading app - Android
- Python: Pandas Rename Series Example - Python
- Use Google Chrome Canvas to create drawings - Chrome
- PowerShell iterate and get all SharePoint sites and sub sites - SharePoint
- How to check if a variable is set in Bash Script or Not - Bash
- How to Show Battery Percentage inside iPhone 12-14 Battery Indicator? - iOS