Skip to content

Instantly share code, notes, and snippets.

@Goliath
Created June 19, 2024 13:31
Show Gist options
  • Save Goliath/e1039902dd7b74cd1f68ba72e10df22f to your computer and use it in GitHub Desktop.
Save Goliath/e1039902dd7b74cd1f68ba72e10df22f to your computer and use it in GitHub Desktop.
Simple code to test how many method invocations you can make before you get stackoverflow exception
public class RecursiveStackOverflow {
static int depth = 0;
private static void recursiveStackOverflow(long param) {
depth++;
recursiveStackOverflow(param);
}
public static void main(String[] args) {
try {
recursiveStackOverflow(1L);
} catch (StackOverflowError e) {
System.out.println("Maximum depth of the call stack is " + depth);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment