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,
- [Fix] java.time.zone.ZoneRulesException: Unknown time-zone ID
- Parse XML file in Java using DOM Parser
- Java equals method - Tutorial
- [Program] How to read three different values using Scanner in Java
- Java: The value of the local variable string is not used
- Display Output in Java Console as a Table
- How to detect Operating System using Java code
- Java 8 Streams map() with examples
- [Fix] java: incompatible types: incompatible parameter types in lambda expression error
- Add newline character Java code example (\r \n \r\n)
- List of Java Major Minor Version Numbers
- IntelliJ Keyboard Shortcut to remove unused imports [Java]
- Java - Check if array contains the value
- [Fix] Java Exception with Lambda - Cannot invoke because object is null
- How to declare and initialize Array in Java Programming
- [Solved] com.sun.xml.ws.transport.http.servlet.WSServletContextListener ClassNotFoundException
- XmlRpcException ConnectException connection refused error
- Create a Zip file using Java Code programmatically
- List of jar files for Jax-ws (SOAP) based Java Web Services
- How to fix Java HTTP java.net.UnknownHostException
- List of jars required for Struts2 project
- [fix] java: incompatible types: double cannot be converted to java.lang.Integer Generics
- Maven BUILD FAILURE: Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin
- Get the current timestamp in Java
- java: unclosed string literal [Error]
More Posts:
- incorrect line ending: found carriage return (\r) without corresponding newline (\n) - Android
- Upload Pdf file using PHP Script - PHP
- Fix zsh: permission denied: script.sh - zsh
- 3 Commands to stop Nginx Server - Linux
- Steps to Compare Two files in Sublime Text Side-by-Side - Sublime-Text
- Android : IOException: Unable to open sync connection! - Android
- Send Email using SharePoint PowerShell command, SMTP server - SharePoint
- How to install pip on macOS using terminal command [Python] - Python