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,
- How to get Java Thread name Example [Program]
- Java 8: Get First and Last Date of the Week for Given Date
- Convert String to int in Java
- How to Get List of All Country Codes in Java Using Locale Class
- Convert Multidimensional Array toString In Java
- [Fix] java: incompatible types: incompatible parameter types in lambda expression error
- Display Era details (AD BC) in Java Date using SimpleDateFormat
- Create a Zip file using Java Code programmatically
- [Fix] java.net.MalformedURLException: unknown protocol
- [fix] Java JDBC ConnectException: Connection refused
- Read Json File and Convert to Java Object using Jackson
- list of jars required for hibernate 4.x.x
- Simple Struts 2 Tutorial in eclipse with tomcat 7 server
- Java: The value of the local variable string is not used
- [fix] URI is not registered (Settings | Languages & Frameworks | Schemas and DTDs) IntelliJ
- Java 8+ get Day of the Week Examples with LocalDateTime, DateTime, ZonalDateTime and Instant classes
- Run SQL Script file using Java JDBC Code Example
- Remove Trailing zeros BigDecimal Java
- Java JDBC IN Clause Example with PreparedStatement MySQL
- Convert Java List to Json String using Jackson
- Java 8 foreach loop code examples
- error: file not found: HelloWorld.java
- IntelliJ Keyboard Shortcut to remove unused imports [Java]
- Exception in thread main java.lang.NoClassDefFoundError: package javaClass
- Struts 2 Hello World Example in Eclipse
More Posts:
- Fetch More then 10 Links Per Page in Google Search Result - Google
- [Fix] MySQL No database selected - ERROR 1046 (3D000) - MySQL
- Sublime Add text at start and end of each line - Sublime
- Rounded Images in Bootstrap framework - Bootstrap
- How to take user input from the console in a Python program - Python
- How to Configure Eclipse keymap in IntelliJ IDE - Android-Studio
- How to get the SharePoint Tenant Login URL - SharePoint
- Fix 0x80070194 Error When Opening Microsoft OneDrive File - Microsoft