-7

What are the reasons for StackOverflowError Exception and whether it is checked or unchecked exception?

SMKReddy
  • 107
  • 3
  • 13
  • Check the elements that you are sending to stack. If You are passing more number of elements to stack, you might get this error.! – Karthikeyan Feb 15 '16 at 12:20
  • `StackOverflowError` extends `Error`. Hence, it is not required to catch it. It often happens when entering an infinite loop of recursive method calls. – Arnaud Denoyelle Feb 15 '16 at 12:21

2 Answers2

3

A StackOverflowError is an Error. Is not an Exception, so is not a checked or unchecked Exception.

The class hierarchy is the following:

                  Throwable
                      |
       +--------------+----------------+
       |                               |
     Error                         Exception 
       |                               |
       |                       +-------+----------------+
       |                       |                        |
StackOverFlowError       RuntimeException         SQLException
                               |
                               |
                      NullPointerException

Errors extends Error.

Checked exceptions extends Exception

Unchecked exceptions extends RuntimeException


This error happens when your stack has too deep calls of methods.

For example if you don't remember to define an exit strategy from a recursive function you can have a StackOverflowError.

Davide Lorenzo MARINO
  • 26,420
  • 4
  • 39
  • 56
1

You could have a glance at https://docs.oracle.com/javase/7/docs/api/java/lang/StackOverflowError.html
to have further information on this error.

Also, a piece of your code could help understand why this error happened.

Lionel Renaux
  • 152
  • 1
  • 14