• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Tim Cooke
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Frank Carver
  • Henry Wong
  • Ron McLeod
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Himai Minh

other situation for StackOverFlowError.

 
Ranch Hand
Posts: 101
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

in which situtation StackOverFlowError will come.

1-in recursion code,but i want to know other situtation where StackOverFlowError will come.
 
lowercase baba
Posts: 13071
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Bartender
Posts: 4568
9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 216
Tomcat Server Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Aaaaaand ... we're on the march. Stylin. Get with it tiny ad.
Garden Master Course kickstarter
https://coderanch.com/t/754577/Garden-Master-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic