StackOverflowError

StackOverflowError()

The function call grew beyond the size of the call stack. This usually happens when a call recurses infinitely.

Examples

The StackOverflowError() function in Julia is raised when the call stack exceeds its maximum size, typically due to infinite recursion.

Example:

julia> function my_recursive_function()
           my_recursive_function()
       end

julia> my_recursive_function()
ERROR: StackOverflowError()
Stacktrace:
 [1] my_recursive_function() at ./REPL[1]:2 (repeats 80000 times)

In this example, my_recursive_function() calls itself infinitely, resulting in a StackOverflowError().

Common mistake example:

julia> function my_function()
           my_function()
       end

julia> try
           my_function()
       catch e
           println("An error occurred: ", e)
       end

In this example, the code attempts to catch the StackOverflowError, but since it occurs during the execution of the function, it cannot be caught within the same call stack. It's important to ensure that recursive functions have proper base cases or termination conditions to avoid StackOverflowError.

See Also

ArgumentError, AssertionError, BoundsError, DivideError, DomainError, EOFError, error, ErrorException, InexactError, InitError, KeyError, LoadError, MethodError, OutOfMemoryError, OverflowError, ParseError, ReadOnlyMemoryError, showerror, StackOverflowError, SystemError, TypeError, UndefRefError, UndefVarError,

User Contributed Notes

Add a Note

The format of note supported is markdown, use triple backtick to start and end a code block.

*Required Field
Details

Checking you are not a robot: