aspose file tools*
The moose likes Beginning Java and the fly likes other situation for StackOverFlowError. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "other situation for StackOverFlowError." Watch "other situation for StackOverFlowError." New topic
Author

other situation for StackOverFlowError.

Ritesh raushan
Ranch Hand

Joined: Aug 29, 2012
Posts: 100

in which situtation StackOverFlowError will come.

1-in recursion code,but i want to know other situtation where StackOverFlowError will come.
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 10908
    
  12

I suppose if method A calls method B which calls method A...or any number of circular calls would do it.

Or if the constructor of an object tries to create an instance of itself...something like



note: it's early, and I haven't had coffee yet, so the above code may not be 100% correct


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Matthew Brown
Bartender

Joined: Apr 06, 2010
Posts: 4240
    
    7

You get a StackOverflowError whenever the stack gets too "deep". Every time a method is called that adds an entry to the stack, which is removed when that method returns. There's a limited amount of memory allocated to this stack, so if you nest method calls too deep then this can happen.

In practice, this limit is pretty large (hundreds or thousands of calls, depending on the memory allocated). You could reach the limit non-recursively if you really wanted to and had a lot of patience. But in practice some form of recursive loop will nearly always be the cause.
Nikhil Sagar
Ranch Hand

Joined: Apr 21, 2012
Posts: 216

Ritesh raushan wrote:
in which situtation StackOverFlowError will come.

1-in recursion code,but i want to know other situtation where StackOverFlowError will come.


Look at the name of this error it is, StackOverFlowError, now what do you think about its perfect name ??
when ever
"Stack Over Flows"
, a StackOverFlowError comes.


OCPJP 6 86%
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: other situation for StackOverFlowError.
 
Similar Threads
q on strings
Checked and JVM Exceptins
Sequence ADT Throwing StackOverflowError
StackOverflowError
Creating Own Object in Method