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. General Programming
  3. C#
  4. Help me iam getting stack overflow exeception , while my solution build successfully , but it threw the stack overflow error

Help me iam getting stack overflow exeception , while my solution build successfully , but it threw the stack overflow error

Scheduled Pinned Locked Moved C#
designhelpcsharpdata-structures
20 Posts 12 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.
  • R radhikasharma

    sir, Thanks for your suggestions, but what is wrong the for each loop , iam not getting as it will For each Character in this charset, as iam getting all the values in the charaset, iam able to initalize the characters in charset, but during looping only iam getting error Am i using wrong method of looping foe each values or it is wrong way of using loop,please tell me the alternate to acheive this with regards Radhika

    T Offline
    T Offline
    Thomas Krojer
    wrote on last edited by
    #6

    I never use goto to exit a loop ....

    R 1 Reply Last reply
    0
    • R radhikasharma

      sir, Thanks for your suggestions, but what is wrong the for each loop , iam not getting as it will For each Character in this charset, as iam getting all the values in the charaset, iam able to initalize the characters in charset, but during looping only iam getting error Am i using wrong method of looping foe each values or it is wrong way of using loop,please tell me the alternate to acheive this with regards Radhika

      OriginalGriffO Offline
      OriginalGriffO Offline
      OriginalGriff
      wrote on last edited by
      #7

      To elaborate on what Thomas said: take a look at your code:

      Label_0104:
      foreach (Character character in this.charSet) ///Error of stack overflow execption in Charset//
      {
      foreach (CharClass class2 in classArray)
      {
      if (character.type == class2)
      {
      num17++;
      goto Label_0104;
      }
      }
      }

      So, you enter the first loop, enter the second, then when you find a match with class2, you go back to before the first loop and enter again. How are you ever going to to get out of the loop? No wonder you run out of memory first!

      No trees were harmed in the sending of this message; however, a significant number of electrons were slightly inconvenienced. This message is made of fully recyclable Zeros and Ones

      "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
      "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

      1 Reply Last reply
      0
      • R radhikasharma

        iam using windows application using csharp,iam design UI which will display the all characters of keyboard(lowercase,uppercase,symbols,special characters)I initialize the characters using folowing code: code 1. private void InitializeCharacters(InkOverlay inkOverlay) { this.Add(new Character(inkOverlay, "0x20", "space", " ", CharClass.Hidden)); this.Add(new Character(inkOverlay, "0x21", "exclam", "!", CharClass.Punctuation)); this.Add(new Character(inkOverlay, "0x22", "quotedbl", "\"", CharClass.Punctuation)); this.Add(new Character(inkOverlay, "0x23", "numbersign", "#", CharClass.Symbol)); this.Add(new Character(inkOverlay, "0x24", "dollar", "$", CharClass.Symbol)); this.Add(new Character(inkOverlay, "0x25", "percent", "%", CharClass.Symbol)); this.Add(new Character(inkOverlay, "0x26", "ampersand", "&", CharClass.Symbol)); this.Add(new Character(inkOverlay, "0x27", "quotesingle", "'",CharClass.Punctuation)); this.Add(new Character(inkOverlay, "0x28", "parenleft", "(", CharClass.Punctuation)); this.Add(new Character(inkOverlay, "0x29", "parenright", ")", CharClass.Punctuation)); this.Add(new Character(inkOverlay, "0x2a", "asterisk", "*", CharClass.Symbol)); this.Add(new Character(inkOverlay, "0x2b", "plus", "+", CharClass.Symbol)); this.Add(new Character(inkOverlay, "0x2c", "comma", ",", CharClass.Punctuation)); this.Add(new Character(inkOverlay, "0x2d", "hyphen", "-", CharClass.Punctuation)); this.Add(new Character(inkOverlay, "0x2e", "period", ".", CharClass.Punctuation)); this.Add(new Character(inkOverlay, "0x2f", "slash", "/", CharClass.Punctuation)); this.Add(new Character(inkOverlay, "0x30", "zero", "0", CharClass.Number)); this.Add(new Character(inkOverlay, "0x31", "one", "1", CharClass.Number)); this.Add(new Character(inkOverlay, "0x32", "two", "2", CharClass.Number)); this.Add(new Character(inkOverlay, "0x33", "three", "3", CharClass.Number)); this.Add(new Character(inkOverlay, "0x34", "four", "4", CharClass.Number)); this.Add(new Character(inkOverlay, "0x35", "five", "5", CharClass.Number)); this.Add(new Character(inkOverlay, "0x36", "six", "6", CharClass.Number)); this.Add(new Characte

        D Offline
        D Offline
        DaveyM69
        wrote on last edited by
        #8

        There is a commonly accepted statement that "goto is evil". That my be a little extreme, but if it is to be used, it should be done with GREAT caution. There are very few cases where goto is the best way to control program flow in modern day languages. Rewrite the code without using any goto(s) (and preferably with more descriptive variable naming) and it will be much easier to follow - and will most likely work!

        Dave
        BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
        Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia)
        Why are you using VB6? Do you hate yourself? (Christian Graus)

        1 Reply Last reply
        0
        • R radhikasharma

          iam using windows application using csharp,iam design UI which will display the all characters of keyboard(lowercase,uppercase,symbols,special characters)I initialize the characters using folowing code: code 1. private void InitializeCharacters(InkOverlay inkOverlay) { this.Add(new Character(inkOverlay, "0x20", "space", " ", CharClass.Hidden)); this.Add(new Character(inkOverlay, "0x21", "exclam", "!", CharClass.Punctuation)); this.Add(new Character(inkOverlay, "0x22", "quotedbl", "\"", CharClass.Punctuation)); this.Add(new Character(inkOverlay, "0x23", "numbersign", "#", CharClass.Symbol)); this.Add(new Character(inkOverlay, "0x24", "dollar", "$", CharClass.Symbol)); this.Add(new Character(inkOverlay, "0x25", "percent", "%", CharClass.Symbol)); this.Add(new Character(inkOverlay, "0x26", "ampersand", "&", CharClass.Symbol)); this.Add(new Character(inkOverlay, "0x27", "quotesingle", "'",CharClass.Punctuation)); this.Add(new Character(inkOverlay, "0x28", "parenleft", "(", CharClass.Punctuation)); this.Add(new Character(inkOverlay, "0x29", "parenright", ")", CharClass.Punctuation)); this.Add(new Character(inkOverlay, "0x2a", "asterisk", "*", CharClass.Symbol)); this.Add(new Character(inkOverlay, "0x2b", "plus", "+", CharClass.Symbol)); this.Add(new Character(inkOverlay, "0x2c", "comma", ",", CharClass.Punctuation)); this.Add(new Character(inkOverlay, "0x2d", "hyphen", "-", CharClass.Punctuation)); this.Add(new Character(inkOverlay, "0x2e", "period", ".", CharClass.Punctuation)); this.Add(new Character(inkOverlay, "0x2f", "slash", "/", CharClass.Punctuation)); this.Add(new Character(inkOverlay, "0x30", "zero", "0", CharClass.Number)); this.Add(new Character(inkOverlay, "0x31", "one", "1", CharClass.Number)); this.Add(new Character(inkOverlay, "0x32", "two", "2", CharClass.Number)); this.Add(new Character(inkOverlay, "0x33", "three", "3", CharClass.Number)); this.Add(new Character(inkOverlay, "0x34", "four", "4", CharClass.Number)); this.Add(new Character(inkOverlay, "0x35", "five", "5", CharClass.Number)); this.Add(new Character(inkOverlay, "0x36", "six", "6", CharClass.Number)); this.Add(new Characte

          A Offline
          A Offline
          Alan N
          wrote on last edited by
          #9

          Label_0104:
          foreach (Character character in this.charSet)
          {
          foreach (CharClass class2 in classArray)
          {
          if (character.type == class2)
          {
          num17++;
          goto Label_0104;
          }
          }
          }

          Stack overflows are often caused by an infinite loop in the code and that's what you have here. When the condition character.type == class2 is true the outer loop restarts and then when the same condition is encountered for a second time, the loop restarts, and so on. I haven't read your code fully but I suspect that you meant to jump to a point after the end of the outer loop, not just before it's start. Alan.

          1 Reply Last reply
          0
          • T Thomas Krojer

            I never use goto to exit a loop ....

            R Offline
            R Offline
            radhikasharma
            wrote on last edited by
            #10

            Ok sir then wat else u use to exit the loop , my problem is that it gives me error only in the For each loop syntax for this.charset statement, so i will try to resolve it but also suggest ur view wat should i use to exit the loop your suggestions are really very helpful thanks alot sir for your kind suggestions with regards radhika

            D 1 Reply Last reply
            0
            • R radhikasharma

              Ok sir then wat else u use to exit the loop , my problem is that it gives me error only in the For each loop syntax for this.charset statement, so i will try to resolve it but also suggest ur view wat should i use to exit the loop your suggestions are really very helpful thanks alot sir for your kind suggestions with regards radhika

              D Offline
              D Offline
              DaveyM69
              wrote on last edited by
              #11

              loops are best exited with break. If you need to know if some condition was met inside the loop, create a variable outside the loop and set it's value before calling break. You can then check that variable after the loop has completed or been broken out of.

              Dave
              BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
              Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia)
              Why are you using VB6? Do you hate yourself? (Christian Graus)

              1 Reply Last reply
              0
              • R radhikasharma

                iam using windows application using csharp,iam design UI which will display the all characters of keyboard(lowercase,uppercase,symbols,special characters)I initialize the characters using folowing code: code 1. private void InitializeCharacters(InkOverlay inkOverlay) { this.Add(new Character(inkOverlay, "0x20", "space", " ", CharClass.Hidden)); this.Add(new Character(inkOverlay, "0x21", "exclam", "!", CharClass.Punctuation)); this.Add(new Character(inkOverlay, "0x22", "quotedbl", "\"", CharClass.Punctuation)); this.Add(new Character(inkOverlay, "0x23", "numbersign", "#", CharClass.Symbol)); this.Add(new Character(inkOverlay, "0x24", "dollar", "$", CharClass.Symbol)); this.Add(new Character(inkOverlay, "0x25", "percent", "%", CharClass.Symbol)); this.Add(new Character(inkOverlay, "0x26", "ampersand", "&", CharClass.Symbol)); this.Add(new Character(inkOverlay, "0x27", "quotesingle", "'",CharClass.Punctuation)); this.Add(new Character(inkOverlay, "0x28", "parenleft", "(", CharClass.Punctuation)); this.Add(new Character(inkOverlay, "0x29", "parenright", ")", CharClass.Punctuation)); this.Add(new Character(inkOverlay, "0x2a", "asterisk", "*", CharClass.Symbol)); this.Add(new Character(inkOverlay, "0x2b", "plus", "+", CharClass.Symbol)); this.Add(new Character(inkOverlay, "0x2c", "comma", ",", CharClass.Punctuation)); this.Add(new Character(inkOverlay, "0x2d", "hyphen", "-", CharClass.Punctuation)); this.Add(new Character(inkOverlay, "0x2e", "period", ".", CharClass.Punctuation)); this.Add(new Character(inkOverlay, "0x2f", "slash", "/", CharClass.Punctuation)); this.Add(new Character(inkOverlay, "0x30", "zero", "0", CharClass.Number)); this.Add(new Character(inkOverlay, "0x31", "one", "1", CharClass.Number)); this.Add(new Character(inkOverlay, "0x32", "two", "2", CharClass.Number)); this.Add(new Character(inkOverlay, "0x33", "three", "3", CharClass.Number)); this.Add(new Character(inkOverlay, "0x34", "four", "4", CharClass.Number)); this.Add(new Character(inkOverlay, "0x35", "five", "5", CharClass.Number)); this.Add(new Character(inkOverlay, "0x36", "six", "6", CharClass.Number)); this.Add(new Characte

                A Offline
                A Offline
                akyriako78
                wrote on last edited by
                #12

                radhikasharma wrote:

                Label_0104: foreach (Character character in this.charSet)///Error of stack overflow execption in Charset// { foreach (CharClass class2 in classArray) { if (character.type == class2) { num17++; goto Label_0104; } } }

                What's that dude ????? Are you trying to live in danger ????? If I close my eyes to the ultimate sin (aka goto) the whole situation smells like an eternal loop.

                R 1 Reply Last reply
                0
                • A akyriako78

                  radhikasharma wrote:

                  Label_0104: foreach (Character character in this.charSet)///Error of stack overflow execption in Charset// { foreach (CharClass class2 in classArray) { if (character.type == class2) { num17++; goto Label_0104; } } }

                  What's that dude ????? Are you trying to live in danger ????? If I close my eyes to the ultimate sin (aka goto) the whole situation smells like an eternal loop.

                  R Offline
                  R Offline
                  radhikasharma
                  wrote on last edited by
                  #13

                  Thanks for your response sir , please tell me the solution and wat iam doing wrong in the for each loop please suggest me the right code so that i will not get any stack overflow exception error also suggest any solution for the above error with regards radhika

                  A 1 Reply Last reply
                  0
                  • R radhikasharma

                    Thanks for your response sir , please tell me the solution and wat iam doing wrong in the for each loop please suggest me the right code so that i will not get any stack overflow exception error also suggest any solution for the above error with regards radhika

                    A Offline
                    A Offline
                    akyriako78
                    wrote on last edited by
                    #14

                    Get rid of these goto statements. They produce the stack overflow. Goto is a relic in modern languages . Use a break statement as mentioned by many other people to exit the loop. Avoid by any means to use goto statements.

                    A R 2 Replies Last reply
                    0
                    • A akyriako78

                      Get rid of these goto statements. They produce the stack overflow. Goto is a relic in modern languages . Use a break statement as mentioned by many other people to exit the loop. Avoid by any means to use goto statements.

                      A Offline
                      A Offline
                      Andrew Rissing
                      wrote on last edited by
                      #15

                      How do you keep a Aggie busy? Write 'Please turn over' on both sides of a piece of paper.

                      1 Reply Last reply
                      0
                      • A akyriako78

                        Get rid of these goto statements. They produce the stack overflow. Goto is a relic in modern languages . Use a break statement as mentioned by many other people to exit the loop. Avoid by any means to use goto statements.

                        R Offline
                        R Offline
                        radhikasharma
                        wrote on last edited by
                        #16

                        Thanks alot sir ,my problem is solved iam very much greatful to you with regards radhika

                        1 Reply Last reply
                        0
                        • R radhikasharma

                          iam using windows application using csharp,iam design UI which will display the all characters of keyboard(lowercase,uppercase,symbols,special characters)I initialize the characters using folowing code: code 1. private void InitializeCharacters(InkOverlay inkOverlay) { this.Add(new Character(inkOverlay, "0x20", "space", " ", CharClass.Hidden)); this.Add(new Character(inkOverlay, "0x21", "exclam", "!", CharClass.Punctuation)); this.Add(new Character(inkOverlay, "0x22", "quotedbl", "\"", CharClass.Punctuation)); this.Add(new Character(inkOverlay, "0x23", "numbersign", "#", CharClass.Symbol)); this.Add(new Character(inkOverlay, "0x24", "dollar", "$", CharClass.Symbol)); this.Add(new Character(inkOverlay, "0x25", "percent", "%", CharClass.Symbol)); this.Add(new Character(inkOverlay, "0x26", "ampersand", "&", CharClass.Symbol)); this.Add(new Character(inkOverlay, "0x27", "quotesingle", "'",CharClass.Punctuation)); this.Add(new Character(inkOverlay, "0x28", "parenleft", "(", CharClass.Punctuation)); this.Add(new Character(inkOverlay, "0x29", "parenright", ")", CharClass.Punctuation)); this.Add(new Character(inkOverlay, "0x2a", "asterisk", "*", CharClass.Symbol)); this.Add(new Character(inkOverlay, "0x2b", "plus", "+", CharClass.Symbol)); this.Add(new Character(inkOverlay, "0x2c", "comma", ",", CharClass.Punctuation)); this.Add(new Character(inkOverlay, "0x2d", "hyphen", "-", CharClass.Punctuation)); this.Add(new Character(inkOverlay, "0x2e", "period", ".", CharClass.Punctuation)); this.Add(new Character(inkOverlay, "0x2f", "slash", "/", CharClass.Punctuation)); this.Add(new Character(inkOverlay, "0x30", "zero", "0", CharClass.Number)); this.Add(new Character(inkOverlay, "0x31", "one", "1", CharClass.Number)); this.Add(new Character(inkOverlay, "0x32", "two", "2", CharClass.Number)); this.Add(new Character(inkOverlay, "0x33", "three", "3", CharClass.Number)); this.Add(new Character(inkOverlay, "0x34", "four", "4", CharClass.Number)); this.Add(new Character(inkOverlay, "0x35", "five", "5", CharClass.Number)); this.Add(new Character(inkOverlay, "0x36", "six", "6", CharClass.Number)); this.Add(new Characte

                          L Offline
                          L Offline
                          Lutoslaw
                          wrote on last edited by
                          #17

                          Where are the num12, num14, num20, num22 and num24 variables? :doh:

                          Greetings - Jacek Gajek

                          J 1 Reply Last reply
                          0
                          • L Lutoslaw

                            Where are the num12, num14, num20, num22 and num24 variables? :doh:

                            Greetings - Jacek Gajek

                            J Offline
                            J Offline
                            Jeremy Tierman
                            wrote on last edited by
                            #18

                            My guess is someone elses DLL was disassembled.

                            E 1 Reply Last reply
                            0
                            • J Jeremy Tierman

                              My guess is someone elses DLL was disassembled.

                              E Offline
                              E Offline
                              Edw
                              wrote on last edited by
                              #19

                              It does look like the output from Reflector when used on a .net assembly, that was built in release mode, with the "Optimize code" box checked. Maybe he should contact the person that wrote the original code to start with, and get the real, (hopefully commented) source. And hope that source isn't copyrighted....

                              1 Reply Last reply
                              0
                              • R radhikasharma

                                iam using windows application using csharp,iam design UI which will display the all characters of keyboard(lowercase,uppercase,symbols,special characters)I initialize the characters using folowing code: code 1. private void InitializeCharacters(InkOverlay inkOverlay) { this.Add(new Character(inkOverlay, "0x20", "space", " ", CharClass.Hidden)); this.Add(new Character(inkOverlay, "0x21", "exclam", "!", CharClass.Punctuation)); this.Add(new Character(inkOverlay, "0x22", "quotedbl", "\"", CharClass.Punctuation)); this.Add(new Character(inkOverlay, "0x23", "numbersign", "#", CharClass.Symbol)); this.Add(new Character(inkOverlay, "0x24", "dollar", "$", CharClass.Symbol)); this.Add(new Character(inkOverlay, "0x25", "percent", "%", CharClass.Symbol)); this.Add(new Character(inkOverlay, "0x26", "ampersand", "&", CharClass.Symbol)); this.Add(new Character(inkOverlay, "0x27", "quotesingle", "'",CharClass.Punctuation)); this.Add(new Character(inkOverlay, "0x28", "parenleft", "(", CharClass.Punctuation)); this.Add(new Character(inkOverlay, "0x29", "parenright", ")", CharClass.Punctuation)); this.Add(new Character(inkOverlay, "0x2a", "asterisk", "*", CharClass.Symbol)); this.Add(new Character(inkOverlay, "0x2b", "plus", "+", CharClass.Symbol)); this.Add(new Character(inkOverlay, "0x2c", "comma", ",", CharClass.Punctuation)); this.Add(new Character(inkOverlay, "0x2d", "hyphen", "-", CharClass.Punctuation)); this.Add(new Character(inkOverlay, "0x2e", "period", ".", CharClass.Punctuation)); this.Add(new Character(inkOverlay, "0x2f", "slash", "/", CharClass.Punctuation)); this.Add(new Character(inkOverlay, "0x30", "zero", "0", CharClass.Number)); this.Add(new Character(inkOverlay, "0x31", "one", "1", CharClass.Number)); this.Add(new Character(inkOverlay, "0x32", "two", "2", CharClass.Number)); this.Add(new Character(inkOverlay, "0x33", "three", "3", CharClass.Number)); this.Add(new Character(inkOverlay, "0x34", "four", "4", CharClass.Number)); this.Add(new Character(inkOverlay, "0x35", "five", "5", CharClass.Number)); this.Add(new Character(inkOverlay, "0x36", "six", "6", CharClass.Number)); this.Add(new Characte

                                J Offline
                                J Offline
                                johannesnestler
                                wrote on last edited by
                                #20

                                Hi radhika! Sorry it's a little late for this reply, but when I looked at your code I nearly cried. I think your problem is solved, so some other suggestions: * Invest some time in learning the basics of the environment and language you are using. (I think you are new to programming) So you learn what type of errors can cause something like StackOverflowException. * Thinking about good variable names is never wasted time. * Posts on any programming forum should never be in the style "I don't understand what you are talking about - just give me the solution" * If something compiles it doesn't mean that it is free of errors - NEVER! It just means it's free of syntax-errors. * If you have written such a long method - think about how to optimize: code length (maybe split into several methods), readability (naming, comments, whitespace), functionality... * Next time you want to use goto: leave it! Another thing: Maybe you had some reason for all your Add(...Character(...)) lines but to me it looks very strange: what about:

                                        for(char ch = (char) 0; ch < 128; ch++)
                                        {
                                            // do something with char
                                        }
                                

                                :rose:

                                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