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. Nice catch!

Nice catch!

Scheduled Pinned Locked Moved The Weird and The Wonderful
debuggingquestion
18 Posts 8 Posters 132 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.
  • W webmarco

    The code below is part of an eventhandler Very informative and easy to debug :(( The worse part is that there are quite a few of these constructions in the application at hand. Shouldn't there be a law against such 'programmers'? ..... try { int startNummer = Convert.ToInt32(dataGrid1[dataGrid1.CurrentRowIndex, 0]); Hashtable ht = Logica.HaalEquipeIDBijStartnummer(editieID); equipeID = (int) ht[startNummer]; if (!Logica.IsTijdControleIngevoerd(etappeID)) return; } catch { return; } ....

    Keep smiling, Marco

    A Offline
    A Offline
    AnthonyC
    wrote on last edited by
    #2

    It is in Dutch. I have no problem reading it, and I don't even speak the language (2 minutes at Babelfish will do it). Get a Dutch programmer to translate it for you. Or does program code always have to be in English?:sigh:

    W E 2 Replies Last reply
    0
    • A AnthonyC

      It is in Dutch. I have no problem reading it, and I don't even speak the language (2 minutes at Babelfish will do it). Get a Dutch programmer to translate it for you. Or does program code always have to be in English?:sigh:

      W Offline
      W Offline
      webmarco
      wrote on last edited by
      #3

      Can you explain to me what is meant by the catch in this piece of code?

      Regards, Marco

      C 1 Reply Last reply
      0
      • W webmarco

        Can you explain to me what is meant by the catch in this piece of code?

        Regards, Marco

        C Offline
        C Offline
        Code_Digger
        wrote on last edited by
        #4

        Sure. It could do with somewhat more comment lines, but the governing logic is clear:   - do some lookups - return immediately if something is wrong: ---- some data is not found when looking it up in "Logica" ---- an exception is thrown, for example in the conversion of text to int32 (hence the catch) - proceed if all assumptions are valid

        W 1 Reply Last reply
        0
        • C Code_Digger

          Sure. It could do with somewhat more comment lines, but the governing logic is clear:   - do some lookups - return immediately if something is wrong: ---- some data is not found when looking it up in "Logica" ---- an exception is thrown, for example in the conversion of text to int32 (hence the catch) - proceed if all assumptions are valid

          W Offline
          W Offline
          webmarco
          wrote on last edited by
          #5

          Aha! so ignore any exception, just return. That is indeed the way to do it. Silly me, what was i thinking?:-O

          Regards, Marco

          J 1 Reply Last reply
          0
          • W webmarco

            The code below is part of an eventhandler Very informative and easy to debug :(( The worse part is that there are quite a few of these constructions in the application at hand. Shouldn't there be a law against such 'programmers'? ..... try { int startNummer = Convert.ToInt32(dataGrid1[dataGrid1.CurrentRowIndex, 0]); Hashtable ht = Logica.HaalEquipeIDBijStartnummer(editieID); equipeID = (int) ht[startNummer]; if (!Logica.IsTijdControleIngevoerd(etappeID)) return; } catch { return; } ....

            Keep smiling, Marco

            M Offline
            M Offline
            Mike Dimmick
            wrote on last edited by
            #6

            Hint: use <pre> when formatting code - much more readable The .NET Framework does supply some operations to find out whether an operation is possible, rather than throw an exception in case of failure. In the case of the above code, you should use int.TryParse instead of Convert.ToInt32 (.NET 2.0 - in .NET 1.x you have to use Double.TryParse then cast to int), which will return a bool to indicate whether it could convert it. Lookups in a Hashtable will also throw an exception if the key isn't found. To avoid this, test for the presence of a key using ContainsKey. Exceptions are slow. Avoid them where not necessary.

            Stability. What an interesting concept. -- Chris Maunder

            W P 2 Replies Last reply
            0
            • M Mike Dimmick

              Hint: use <pre> when formatting code - much more readable The .NET Framework does supply some operations to find out whether an operation is possible, rather than throw an exception in case of failure. In the case of the above code, you should use int.TryParse instead of Convert.ToInt32 (.NET 2.0 - in .NET 1.x you have to use Double.TryParse then cast to int), which will return a bool to indicate whether it could convert it. Lookups in a Hashtable will also throw an exception if the key isn't found. To avoid this, test for the presence of a key using ContainsKey. Exceptions are slow. Avoid them where not necessary.

              Stability. What an interesting concept. -- Chris Maunder

              W Offline
              W Offline
              webmarco
              wrote on last edited by
              #7

              Exactly my point, a catch block is to handle unexpected exceptions, not for program logic. If the exception is not being handled by the catch block, whats the point in using it? Thank you for your comment Mike.

              Regards, Marco

              1 Reply Last reply
              0
              • M Mike Dimmick

                Hint: use <pre> when formatting code - much more readable The .NET Framework does supply some operations to find out whether an operation is possible, rather than throw an exception in case of failure. In the case of the above code, you should use int.TryParse instead of Convert.ToInt32 (.NET 2.0 - in .NET 1.x you have to use Double.TryParse then cast to int), which will return a bool to indicate whether it could convert it. Lookups in a Hashtable will also throw an exception if the key isn't found. To avoid this, test for the presence of a key using ContainsKey. Exceptions are slow. Avoid them where not necessary.

                Stability. What an interesting concept. -- Chris Maunder

                P Offline
                P Offline
                PIEBALDconsult
                wrote on last edited by
                #8

                Mike Dimmick wrote:

                Exceptions are slow.

                http://www.codeproject.com/dotnet/ExceptionPerformance.asp[^]

                Mike Dimmick wrote:

                Avoid them where not necessary.

                Well, yeah, but don't go out of your way to do so.

                --| "Every tool is a hammer." |--

                1 Reply Last reply
                0
                • A AnthonyC

                  It is in Dutch. I have no problem reading it, and I don't even speak the language (2 minutes at Babelfish will do it). Get a Dutch programmer to translate it for you. Or does program code always have to be in English?:sigh:

                  E Offline
                  E Offline
                  Erik Burger
                  wrote on last edited by
                  #9

                  arc_10spd wrote:

                  Or does program code always have to be in English?

                  If you ever want to start a lobby for making a law that states that all code should be in English, I'll make the buttons :cool:

                  A 1 Reply Last reply
                  0
                  • E Erik Burger

                    arc_10spd wrote:

                    Or does program code always have to be in English?

                    If you ever want to start a lobby for making a law that states that all code should be in English, I'll make the buttons :cool:

                    A Offline
                    A Offline
                    AnthonyC
                    wrote on last edited by
                    #10

                    There are about currently about 4,000 unique languages remaining in the world. English will overrun most of them within the next 100 years at the cost of an extraordinary and fascinating diversity in human culture and history stretching back for over 10,000 years (at least that is what some historical linguists claim they can reconstruct). I for one would find it a tragedy if Dutch were to go as well ("not so much a language as an organised method for clearing one's throat"). However, ErikDD, if you MUST have it in English, here is a guess: .... try { int startNumber = Convert.ToInt32(dataGrid1[dataGrid1.CurrentRowIndex, 0]); Hashtable ht = Logic.ObtainTeamIDAtStartnumber(editID); teamID = (int) ht[Startnumber]; if (!Logic.IsTimeControlIntroduced(teamID) return; } catch { return; } ... ;P

                    A E 2 Replies Last reply
                    0
                    • A AnthonyC

                      There are about currently about 4,000 unique languages remaining in the world. English will overrun most of them within the next 100 years at the cost of an extraordinary and fascinating diversity in human culture and history stretching back for over 10,000 years (at least that is what some historical linguists claim they can reconstruct). I for one would find it a tragedy if Dutch were to go as well ("not so much a language as an organised method for clearing one's throat"). However, ErikDD, if you MUST have it in English, here is a guess: .... try { int startNumber = Convert.ToInt32(dataGrid1[dataGrid1.CurrentRowIndex, 0]); Hashtable ht = Logic.ObtainTeamIDAtStartnumber(editID); teamID = (int) ht[Startnumber]; if (!Logic.IsTimeControlIntroduced(teamID) return; } catch { return; } ... ;P

                      A Offline
                      A Offline
                      AnthonyC
                      wrote on last edited by
                      #11

                      Sorry. Probably should translate etappe as "stage": ... if (!Logic.IsTimeControlIntroduced(stageID) ... not ... if (!Logic.IsTimeControlIntroduced((editID)) ... :-O

                      1 Reply Last reply
                      0
                      • A AnthonyC

                        There are about currently about 4,000 unique languages remaining in the world. English will overrun most of them within the next 100 years at the cost of an extraordinary and fascinating diversity in human culture and history stretching back for over 10,000 years (at least that is what some historical linguists claim they can reconstruct). I for one would find it a tragedy if Dutch were to go as well ("not so much a language as an organised method for clearing one's throat"). However, ErikDD, if you MUST have it in English, here is a guess: .... try { int startNumber = Convert.ToInt32(dataGrid1[dataGrid1.CurrentRowIndex, 0]); Hashtable ht = Logic.ObtainTeamIDAtStartnumber(editID); teamID = (int) ht[Startnumber]; if (!Logic.IsTimeControlIntroduced(teamID) return; } catch { return; } ... ;P

                        E Offline
                        E Offline
                        Erik Burger
                        wrote on last edited by
                        #12

                        *grins* I happen to be one of the relatively few people who actually speak Dutch (aka a Dutchman) but I do appreciate the effort :) As for Dutch disappearing, I wouldn't miss it, but I don't enjoy the prospect. It's just that I also believe in code mobility and reusability.

                        P A 2 Replies Last reply
                        0
                        • E Erik Burger

                          *grins* I happen to be one of the relatively few people who actually speak Dutch (aka a Dutchman) but I do appreciate the effort :) As for Dutch disappearing, I wouldn't miss it, but I don't enjoy the prospect. It's just that I also believe in code mobility and reusability.

                          P Offline
                          P Offline
                          PIEBALDconsult
                          wrote on last edited by
                          #13

                          That would put a new spin on our local culture here outside Phoenix too; we just had our annual "Lost Dutchman Days" festival.

                          --| "Every tool is a hammer." |--

                          1 Reply Last reply
                          0
                          • W webmarco

                            Aha! so ignore any exception, just return. That is indeed the way to do it. Silly me, what was i thinking?:-O

                            Regards, Marco

                            J Offline
                            J Offline
                            JohnnySacks
                            wrote on last edited by
                            #14

                            Really, what were you thinking. Will the end user report any mysterious issues before you manage to get a new and better job? Besides, 'some day' we're going to integrate an error capture and/or logging methodology into this business critical high visibility application which re-engineers our business case to leverage best-practice synergies to pro actively actualize our bottom line but at this point we really don't know what features are required and we're REALLY in a hurry to get something done so for now, we'll just put the blocks in place and fill them in later. Every application I support in this place is filled with this crap. Every programmer who spews this crap out rapidly is a hero (and soon off to bigger and better jobs)

                            E 1 Reply Last reply
                            0
                            • E Erik Burger

                              *grins* I happen to be one of the relatively few people who actually speak Dutch (aka a Dutchman) but I do appreciate the effort :) As for Dutch disappearing, I wouldn't miss it, but I don't enjoy the prospect. It's just that I also believe in code mobility and reusability.

                              A Offline
                              A Offline
                              AnthonyC
                              wrote on last edited by
                              #15

                              ErikDD wrote:

                              *grins* I happen to be one of the relatively few people who actually speak Dutch (aka a Dutchman) but I do appreciate the effort

                              ErikDD, A hidden Dutchman! Very drole. And very hard to tell from your English, of course. I have always thought the Dutch speak the best English in Europe. BTW, how was my Dutch translation of the code? I speak English, French, German and two Australian Aboriginal languages, but alas no Dutch, which, if I could find the time I would try to learn. I also have only a Dutch to German phrase book (relic of a vacation in Amsterdam when I lived in Germany 20 years ago), so it was a bit tricky trying to put together a proper translation, and you don't get any nuances from Babelfish. Thanks for the sly humour! You definitely made me laugh. :laugh: Anthony

                              H E 2 Replies Last reply
                              0
                              • A AnthonyC

                                ErikDD wrote:

                                *grins* I happen to be one of the relatively few people who actually speak Dutch (aka a Dutchman) but I do appreciate the effort

                                ErikDD, A hidden Dutchman! Very drole. And very hard to tell from your English, of course. I have always thought the Dutch speak the best English in Europe. BTW, how was my Dutch translation of the code? I speak English, French, German and two Australian Aboriginal languages, but alas no Dutch, which, if I could find the time I would try to learn. I also have only a Dutch to German phrase book (relic of a vacation in Amsterdam when I lived in Germany 20 years ago), so it was a bit tricky trying to put together a proper translation, and you don't get any nuances from Babelfish. Thanks for the sly humour! You definitely made me laugh. :laugh: Anthony

                                H Offline
                                H Offline
                                Hal Angseesing
                                wrote on last edited by
                                #16

                                arc_10spd wrote:

                                I have always thought the Dutch speak the best English in Europe

                                What better than the British? Yeah, you may have a point - have you heard some of our dialects! :-D

                                1 Reply Last reply
                                0
                                • A AnthonyC

                                  ErikDD wrote:

                                  *grins* I happen to be one of the relatively few people who actually speak Dutch (aka a Dutchman) but I do appreciate the effort

                                  ErikDD, A hidden Dutchman! Very drole. And very hard to tell from your English, of course. I have always thought the Dutch speak the best English in Europe. BTW, how was my Dutch translation of the code? I speak English, French, German and two Australian Aboriginal languages, but alas no Dutch, which, if I could find the time I would try to learn. I also have only a Dutch to German phrase book (relic of a vacation in Amsterdam when I lived in Germany 20 years ago), so it was a bit tricky trying to put together a proper translation, and you don't get any nuances from Babelfish. Thanks for the sly humour! You definitely made me laugh. :laugh: Anthony

                                  E Offline
                                  E Offline
                                  Erik Burger
                                  wrote on last edited by
                                  #17

                                  I wouldn't have guessed from your translation that you weren't a Dutch speaker, it was right on the mark :) As for the homour..I have my good days ;P Erik

                                  1 Reply Last reply
                                  0
                                  • J JohnnySacks

                                    Really, what were you thinking. Will the end user report any mysterious issues before you manage to get a new and better job? Besides, 'some day' we're going to integrate an error capture and/or logging methodology into this business critical high visibility application which re-engineers our business case to leverage best-practice synergies to pro actively actualize our bottom line but at this point we really don't know what features are required and we're REALLY in a hurry to get something done so for now, we'll just put the blocks in place and fill them in later. Every application I support in this place is filled with this crap. Every programmer who spews this crap out rapidly is a hero (and soon off to bigger and better jobs)

                                    E Offline
                                    E Offline
                                    Erik Burger
                                    wrote on last edited by
                                    #18

                                    JohnnySacks wrote:

                                    Besides, 'some day' we're going to integrate an error capture and/or logging methodology into this business critical high visibility application which re-engineers our business case to leverage best-practice synergies to pro actively actualize our bottom line but at this point we really don't know what features are required and we're REALLY in a hurry to get something done so for now, we'll just put the blocks in place and fill them in later.

                                    This sounds so scarily like my manager..no wonder we've decided not to listen to him anymore ;P

                                    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