Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6148571
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T19:18:20+00:00 2026-05-23T19:18:20+00:00

I’m not exactly sure what a stack overflow exception is. I got this error

  • 0

I’m not exactly sure what a stack overflow exception is. I got this error when I called a method in another form.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T19:18:21+00:00Added an answer on May 23, 2026 at 7:18 pm

    Sometimes programs misbehave. Programmers write their programs by implementing some logic and then testing that it works correctly. But if the programmer makes a mistake in the logic, bad things can happen.

    Probably one of the most common ways that a program can go awry is with an infinite loop. Take this sample program that tries to add up the first n integers:

    static int Sum(int n)
    {
        int sum = 0;
        int i = 1;
        while (i <= n)
            sum += i;
        return sum;
    }
    

    What will happen? Where’s the bug? We forgot to increment i and so it will never exceed n. When you just run this it runs and hangs. It will never stop on its own.

    But if you have an infinite loop in a program and you use resources in that loop, you could run out of resources. Let’s take another program that uses recursion to find the sum:

    static int RecursiveSum(int n)
    {
        return n + RecursiveSum(n - 1);
    }
    

    This method is also buggy. It too has an “infinite loop” because we forgot to include the termination condition. What happens when we run it?

    Process is terminated due to StackOverflowException.

    In C# every time you call a method you use up a little of a resource called a stack. The stack allows the program to keep track of who called who so that when methods return, it returns to the right place. Method arguments and local variables also use up stack space. When methods end and return, they free up the stack space that they used.

    The problem is that the stack uses memory and so it is not an infinite resource like time!

    So there are two primary ways that a program can produce a StackOverflowException:

    1. An infinite loop of methods calling methods calling methods that never return
    2. A series of too many recursive call levels that would end eventually, but the stack runs out first

    The first problem is demonstrated by the second method above. But even if we fix that method to add a termination condition, while it will work for smaller numbers it will eventually fail before producing a sum for sufficiently large values of n.

    Most garden variety StackOverflowExceptions are of the first type but if you don’t use recursion carefully in your methods you can run into the second problem as well.

    When debugging a StackOverflowException the call stack will often look like this:

    ...
    Program.RecursiveSum(int n = -7770) Line 26 + 0xf bytes C#
    Program.RecursiveSum(int n = -7769) Line 26 + 0xf bytes C#
    Program.RecursiveSum(int n = -7768) Line 26 + 0xf bytes C#
    Program.RecursiveSum(int n = -7767) Line 26 + 0xf bytes C#
    Program.RecursiveSum(int n = -7766) Line 26 + 0xf bytes C#
    The maximum number of stack frames supported by Visual Studio has been exceeded.    
    

    or sometimes A calls B which calls C and then calls A again, etc. You just have to find the loop, set a breakpoint in in, a diagnose what is going on.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
For some reason, after submitting a string like this Jack’s Spindle from a text
link Im having trouble converting the html entites into html characters, (&# 8217;) i
this is what i have right now Drawing an RSS feed into the php,
I've got a string that has curly quotes in it. I'd like to replace
I have some data like this: 1 2 3 4 5 9 2 6
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have a text area in my form which accepts all possible characters from
I need a function that will clean a strings' special characters. I do NOT
Does anyone know how can I replace this 2 symbol below from the string

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.