Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Other Discussions
  3. The Weird and The Wonderful
  4. StackOverFlowException

StackOverFlowException

Scheduled Pinned Locked Moved The Weird and The Wonderful
csharpdotnetcomquestionannouncement
14 Posts 8 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Natza Mitzi

    MS are not letting you to catch a StackOverFlowException. I wrote a evaluator/interperter using C# 1.1 . The language supports recursion about a year ago I moved to C# 2.0 and only now we found out that a too deep of a recursion throws the application without any notice. It just goes away. A simple factorial like: fact(n)(if(n == 0,1,n * fact(n-1))) vaporizes the application at fact(46) I checked MSDN and it says: Starting with the .NET Framework version 2.0, a StackOverflowException object cannot be caught by a try-catch block and the corresponding process is terminated by default http://msdn.microsoft.com/en-us/library/system.stackoverflowexception.aspx On this page they tell you to stay away from unbound recursions. What kind of recommendation is this? Guys stay away from null pointers!!

    Natza Mitzi

    L Offline
    L Offline
    leppie
    wrote on last edited by
    #2

    Natza Mitzi wrote:

    MS are not letting you to catch a StackOverFlowException. I wrote a evaluator/interperter using C# 1.1 . The language supports recursion about a year ago I moved to C# 2.0 and only now we found out that a too deep of a recursion throws the application without any notice. It just goes away. A simple factorial like: fact(n)(if(n == 0,1,n * fact(n-1))) vaporizes the application at fact(46)

    That's how the CLR works. In fact even a tail recursive language like Scheme will fail on that. You have 2 options: 1. Increase stack space. 2. Rewrite to use iteration or tail-recursion.

    xacc.ide - now with TabsToSpaces support
    IronScheme - 1.0 alpha 4a out now (29 May 2008)

    1 Reply Last reply
    0
    • N Natza Mitzi

      MS are not letting you to catch a StackOverFlowException. I wrote a evaluator/interperter using C# 1.1 . The language supports recursion about a year ago I moved to C# 2.0 and only now we found out that a too deep of a recursion throws the application without any notice. It just goes away. A simple factorial like: fact(n)(if(n == 0,1,n * fact(n-1))) vaporizes the application at fact(46) I checked MSDN and it says: Starting with the .NET Framework version 2.0, a StackOverflowException object cannot be caught by a try-catch block and the corresponding process is terminated by default http://msdn.microsoft.com/en-us/library/system.stackoverflowexception.aspx On this page they tell you to stay away from unbound recursions. What kind of recommendation is this? Guys stay away from null pointers!!

      Natza Mitzi

      CPalliniC Online
      CPalliniC Online
      CPallini
      wrote on last edited by
      #3

      Natza Mitzi wrote:

      Guys stay away from null pointers!!

      And from people posting on the wrong forum. :-D

      If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
      This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
      [My articles]

      In testa che avete, signor di Ceprano?

      P D 2 Replies Last reply
      0
      • CPalliniC CPallini

        Natza Mitzi wrote:

        Guys stay away from null pointers!!

        And from people posting on the wrong forum. :-D

        If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
        This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
        [My articles]

        P Offline
        P Offline
        Paul Conrad
        wrote on last edited by
        #4

        CPallini wrote:

        people posting on the wrong forum

        Geeze, another one :laugh:

        "The clue train passed his station without stopping." - John Simmons / outlaw programmer "Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon

        CPalliniC 1 Reply Last reply
        0
        • P Paul Conrad

          CPallini wrote:

          people posting on the wrong forum

          Geeze, another one :laugh:

          "The clue train passed his station without stopping." - John Simmons / outlaw programmer "Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon

          CPalliniC Online
          CPalliniC Online
          CPallini
          wrote on last edited by
          #5

          Yes, another one. :-D

          If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
          This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
          [My articles]

          In testa che avete, signor di Ceprano?

          P 1 Reply Last reply
          0
          • CPalliniC CPallini

            Natza Mitzi wrote:

            Guys stay away from null pointers!!

            And from people posting on the wrong forum. :-D

            If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
            This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
            [My articles]

            D Offline
            D Offline
            Dan Neely
            wrote on last edited by
            #6

            CPallini wrote:

            And from people posting on the wrong forum.

            That throws WrongForumException and UraNoobException, neither of which are derived from StackOverFlowException.

            Today's lesson is brought to you by the word "niggardly". Remember kids, don't attribute to racism what can be explained by Scandinavian language roots. -- Robert Royall

            N 1 Reply Last reply
            0
            • CPalliniC CPallini

              Yes, another one. :-D

              If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
              This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
              [My articles]

              P Offline
              P Offline
              Paul Conrad
              wrote on last edited by
              #7

              Seems like a rash of 'em lately :suss:

              "The clue train passed his station without stopping." - John Simmons / outlaw programmer "Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon

              J 1 Reply Last reply
              0
              • D Dan Neely

                CPallini wrote:

                And from people posting on the wrong forum.

                That throws WrongForumException and UraNoobException, neither of which are derived from StackOverFlowException.

                Today's lesson is brought to you by the word "niggardly". Remember kids, don't attribute to racism what can be explained by Scandinavian language roots. -- Robert Royall

                N Offline
                N Offline
                Natza Mitzi
                wrote on last edited by
                #8

                You either have problems understanding the issue or just happy to jump in with someone that can not understand the issue.

                Natza Mitzi

                1 Reply Last reply
                0
                • N Natza Mitzi

                  MS are not letting you to catch a StackOverFlowException. I wrote a evaluator/interperter using C# 1.1 . The language supports recursion about a year ago I moved to C# 2.0 and only now we found out that a too deep of a recursion throws the application without any notice. It just goes away. A simple factorial like: fact(n)(if(n == 0,1,n * fact(n-1))) vaporizes the application at fact(46) I checked MSDN and it says: Starting with the .NET Framework version 2.0, a StackOverflowException object cannot be caught by a try-catch block and the corresponding process is terminated by default http://msdn.microsoft.com/en-us/library/system.stackoverflowexception.aspx On this page they tell you to stay away from unbound recursions. What kind of recommendation is this? Guys stay away from null pointers!!

                  Natza Mitzi

                  L Offline
                  L Offline
                  Luc Pattyn
                  wrote on last edited by
                  #9

                  Natza Mitzi wrote:

                  Starting with the .NET Framework version 2.0, a StackOverflowException object cannot be caught by a try-catch block and the corresponding process is terminated by default

                  yes, that is unfortunate. On the other hand, recovering from a stack overflow in a reliable way is probably rather tricky.

                  Natza Mitzi wrote:

                  A simple factorial like: fact(n)(if(n == 0,1,n * fact(n-1))) vaporizes the application at fact(46)

                  That is crap. How much does one stack frame take, 100 bytes? 1KB? Now take 46 of those and your stack has run out??? IIRC the default stack size is 1 MB. I just ran a little test and 10000! runs just fine. :)

                  Luc Pattyn [Forum Guidelines] [My Articles]


                  Voting for dummies? No thanks. X|


                  1 Reply Last reply
                  0
                  • N Natza Mitzi

                    MS are not letting you to catch a StackOverFlowException. I wrote a evaluator/interperter using C# 1.1 . The language supports recursion about a year ago I moved to C# 2.0 and only now we found out that a too deep of a recursion throws the application without any notice. It just goes away. A simple factorial like: fact(n)(if(n == 0,1,n * fact(n-1))) vaporizes the application at fact(46) I checked MSDN and it says: Starting with the .NET Framework version 2.0, a StackOverflowException object cannot be caught by a try-catch block and the corresponding process is terminated by default http://msdn.microsoft.com/en-us/library/system.stackoverflowexception.aspx On this page they tell you to stay away from unbound recursions. What kind of recommendation is this? Guys stay away from null pointers!!

                    Natza Mitzi

                    L Offline
                    L Offline
                    Lost User
                    wrote on last edited by
                    #10

                    I can use a recursive factorial with numbers up to and including 170 Any higher overflows the UInt1024 that I used for it - no StackOverFlowException So what happened there? Though I agree that the advice is pointless..

                    N 2 Replies Last reply
                    0
                    • L Lost User

                      I can use a recursive factorial with numbers up to and including 170 Any higher overflows the UInt1024 that I used for it - no StackOverFlowException So what happened there? Though I agree that the advice is pointless..

                      N Offline
                      N Offline
                      Natza Mitzi
                      wrote on last edited by
                      #11

                      I think that it depends on: a) The cost of opening a function on the stack changes b) Whether the recursion is a tail recursion or not

                      Natza Mitzi

                      1 Reply Last reply
                      0
                      • P Paul Conrad

                        Seems like a rash of 'em lately :suss:

                        "The clue train passed his station without stopping." - John Simmons / outlaw programmer "Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon

                        J Offline
                        J Offline
                        Jonathan C Dickinson
                        wrote on last edited by
                        #12

                        I think his point might have been a coding horror on the part of Microsoft.

                        He who asks a question is a fool for five minutes. He who does not ask a question remains a fool forever. [Chineese Proverb] Jonathan C Dickinson (C# Software Engineer)

                        1 Reply Last reply
                        0
                        • N Natza Mitzi

                          MS are not letting you to catch a StackOverFlowException. I wrote a evaluator/interperter using C# 1.1 . The language supports recursion about a year ago I moved to C# 2.0 and only now we found out that a too deep of a recursion throws the application without any notice. It just goes away. A simple factorial like: fact(n)(if(n == 0,1,n * fact(n-1))) vaporizes the application at fact(46) I checked MSDN and it says: Starting with the .NET Framework version 2.0, a StackOverflowException object cannot be caught by a try-catch block and the corresponding process is terminated by default http://msdn.microsoft.com/en-us/library/system.stackoverflowexception.aspx On this page they tell you to stay away from unbound recursions. What kind of recommendation is this? Guys stay away from null pointers!!

                          Natza Mitzi

                          N Offline
                          N Offline
                          Natza Mitzi
                          wrote on last edited by
                          #13

                          I reduced the occurrence of the problem by splitting some methods and using a dictionary instead of large switches that cause stack bloats. Now a simple recursive factorial method works with 400 instead of 46, that is almost 900% better

                          Natza Mitzi

                          1 Reply Last reply
                          0
                          • L Lost User

                            I can use a recursive factorial with numbers up to and including 170 Any higher overflows the UInt1024 that I used for it - no StackOverFlowException So what happened there? Though I agree that the advice is pointless..

                            N Offline
                            N Offline
                            Natza Mitzi
                            wrote on last edited by
                            #14

                            My answer below: I reduced the occurrence of the problem by splitting some methods and using a dictionary instead of large switches that cause stack bloats. Now a simple recursive factorial method works with 400 instead of 46, that is almost 900% better

                            Natza Mitzi

                            1 Reply Last reply
                            0
                            Reply
                            • Reply as topic
                            Log in to reply
                            • Oldest to Newest
                            • Newest to Oldest
                            • Most Votes


                            • Login

                            • Don't have an account? Register

                            • Login or register to search.
                            • First post
                              Last post
                            0
                            • Categories
                            • Recent
                            • Tags
                            • Popular
                            • World
                            • Users
                            • Groups