Questions tagged [stack-overflow]

NOT THIS WEBSITE! Use this tag for the error caused by pushing too many items onto the callstack. If you have a question regarding this website, please go to https://meta.stackoverflow.com

DO NOT USE THIS TAG TO REFER TO THE STACK OVERFLOW WEBSITE! If you have a question regarding the site, please go to Meta.


In software, a stack overflow occurs if the call stack pointer exceeds the stack bound. The call stack may consist of a limited amount of address space, often determined at the start of the program. The size of the call stack depends on many factors, including the programming language, machine architecture, multi-threading, and amount of available memory. When a program attempts to use more space than is available on the call stack (that is, when it attempts to access memory beyond the call stack's bounds, which is essentially a buffer overflow), the stack is said to overflow, typically resulting in a program crash.

(Wikipedia: Stack overflow)

See How does a “stack overflow” occur and how do you prevent it? for general advice on stack overflow exceptions, what they are, etc.

See also:

4171 questions
527
votes
15 answers

What is a StackOverflowError?

What is a StackOverflowError, what causes it, and how should I deal with them?
Ziggy
  • 21,845
  • 28
  • 75
  • 104
334
votes
6 answers

Try-finally block prevents StackOverflowError

Take a look at the following two methods: public static void foo() { try { foo(); } finally { foo(); } } public static void bar() { bar(); } Running bar() clearly results in a StackOverflowError, but running foo()…
arshajii
  • 127,459
  • 24
  • 238
  • 287
236
votes
10 answers

What actually causes a Stack Overflow error?

I've looked everywhere and can't find a solid answer. According to the documentation, Java throws a java.lang.StackOverflowError error under the following circumstance: Thrown when a stack overflow occurs because an application recurses too…
retrohacker
  • 3,194
  • 4
  • 21
  • 31
154
votes
9 answers

How to increase the Java stack size?

I asked this question to get to know how to increase the runtime call stack size in the JVM. I've got an answer to this, and I've also got many useful answers and comments relevant to how Java handles the situation where a large runtime stack is…
pts
  • 80,836
  • 20
  • 110
  • 183
140
votes
9 answers

How does a "stack overflow" occur and how do you prevent it?

How does a stack overflow occur and what are the ways to make sure it doesn't happen, or ways to prevent one?
JasonMichael
  • 2,463
  • 4
  • 26
  • 25
135
votes
10 answers

C# catch a stack overflow exception

I have a recursive call to a method that throws a stack overflow exception. The first call is surrounded by a try catch block but the exception is not caught. Does the stack overflow exception behave in a special way? Can I catch/handle the…
Toto
  • 7,491
  • 18
  • 50
  • 72
127
votes
10 answers

Chrome/jQuery Uncaught RangeError: Maximum call stack size exceeded

I am getting the error "Uncaught RangeError: Maximum call stack size exceeded" on chrome. here is my jQuery function $('td').click(function () { if ($(this).context.id != null && $(this).context.id != '') { foo($('#docId').val(),…
Andy
  • 10,412
  • 13
  • 70
  • 95
122
votes
2 answers

Why is #include preventing a stack overflow error here?

This is my sample code: #include #include using namespace std; class MyClass { string figName; public: MyClass(const string& s) { figName = s; } const string& getName() const { return…
airborne
  • 3,664
  • 4
  • 15
  • 27
113
votes
13 answers

What causes a java.lang.StackOverflowError

What can cause a java.lang.StackOverflowError? The stack printout that I get is not very deep at all (only 5 methods).
Ivan
  • 1,159
  • 2
  • 8
  • 4
111
votes
7 answers

Why does this method print 4?

I was wondering what happens when you try to catch an StackOverflowError and came up with the following method: class RandomNumberGenerator { static int cnt = 0; public static void main(String[] args) { try { …
flrnb
  • 836
  • 1
  • 7
  • 13
105
votes
12 answers

Node.js - Maximum call stack size exceeded

When I run my code, Node.js throws a "RangeError: Maximum call stack size exceeded" exception caused by too many recursive calls. I tried to increase Node.js stack size by sudo node --stack-size=16000 app, but Node.js crashes without any error…
user1518183
  • 4,651
  • 5
  • 28
  • 39
103
votes
15 answers

gson.toJson() throws StackOverflowError

I would like to generate a JSON String from my object: Gson gson = new Gson(); String json = gson.toJson(item); Everytime I try to do this, I get this error: 14:46:40,236 ERROR [[BomItemToJSON]] Servlet.service() for servlet BomItemToJSON threw…
nimrod
  • 5,595
  • 29
  • 85
  • 149
102
votes
5 answers

Why is it possible to recover from a StackOverflowError?

I'm surprised at how it is possible to continue execution even after a StackOverflowError has occurred in Java. I know that StackOverflowError is a sublass of the class Error. The class Error is decumented as "a subclass of Throwable that indicates…
user3370796
  • 1,060
  • 1
  • 7
  • 7
81
votes
10 answers

What is the difference between a stack overflow and buffer overflow?

What is the difference between a stack overflow and a buffer overflow in programming?
joe
  • 34,529
  • 29
  • 100
  • 137
79
votes
15 answers

Hibernate OneToMany java.lang.StackOverflowError

It's my first question here on stack, so please be gentle :D I'm trying to create hibernate OneToMany relationship. When I try to fetch some data from my DB, I'm getting StackOverflowError. But when i remove OneToMany part, everything goes normally.…
otocon
  • 1,029
  • 1
  • 8
  • 15
1
2 3
99 100