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. Does this count?

Does this count?

Scheduled Pinned Locked Moved The Weird and The Wonderful
helpquestion
17 Posts 10 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.
  • J jamie550

    Is there a reason for this appearing all over the code???

    try
    {
    if (something is wrong)
    throw new exceptionaboutwhateveriswring();
    //If nothing was wrong
    ...
    ...
    ...
    continue work
    }
    catch (whatever exception was just thrown)
    {
    Console.WriteLine(information about the error);
    }

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

    Sure does. Yeah, that's bad; catching your own exception is like laughing at your own joke. Or other behaviours less kid sister friendly.

    1 Reply Last reply
    0
    • J jamie550

      Is there a reason for this appearing all over the code???

      try
      {
      if (something is wrong)
      throw new exceptionaboutwhateveriswring();
      //If nothing was wrong
      ...
      ...
      ...
      continue work
      }
      catch (whatever exception was just thrown)
      {
      Console.WriteLine(information about the error);
      }

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

      Probably written by a VB'r. I have seen that pattern used abundantly.

      xacc.ide - now with TabsToSpaces support
      IronScheme - 1.0 alpha 3 out now

      D 1 Reply Last reply
      0
      • L leppie

        Probably written by a VB'r. I have seen that pattern used abundantly.

        xacc.ide - now with TabsToSpaces support
        IronScheme - 1.0 alpha 3 out now

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

        Only because C# doesn't support On Error Resume Next :((

        You know, every time I tried to win a bar-bet about being able to count to 1000 using my fingers I always get punched out when I reach 4.... -- El Corazon

        S P 2 Replies Last reply
        0
        • D Dan Neely

          Only because C# doesn't support On Error Resume Next :((

          You know, every time I tried to win a bar-bet about being able to count to 1000 using my fingers I always get punched out when I reach 4.... -- El Corazon

          S Offline
          S Offline
          Stephen Hewitt
          wrote on last edited by
          #10

          dan neely wrote:

          Only because C# doesn't support On Error Resume Next

          Thankfully.

          Steve

          1 Reply Last reply
          0
          • L Luc Pattyn

            No problem. You'll catch on soon enough. :)

            Luc Pattyn [Forum Guidelines] [My Articles]


            This month's tips: - before you ask a question here, search CodeProject, then Google; - the quality and detail of your question reflects on the effectiveness of the help you are likely to get; - use PRE tags to preserve formatting when showing multi-line code snippets.


            M Offline
            M Offline
            MarkB777
            wrote on last edited by
            #11

            "You'll **catch** on soon enough" :D.

            Mark Brock Click here to view my blog

            Z 1 Reply Last reply
            0
            • D Dan Neely

              Only because C# doesn't support On Error Resume Next :((

              You know, every time I tried to win a bar-bet about being able to count to 1000 using my fingers I always get punched out when I reach 4.... -- El Corazon

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

              No, that would be

              try
              {
              // One statement
              }
              catch
              {
              // Ignore Exception
              }

              L 1 Reply Last reply
              0
              • P PIEBALDconsult

                No, that would be

                try
                {
                // One statement
                }
                catch
                {
                // Ignore Exception
                }

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

                PIEBALDconsult wrote:

                // Ignore Exception

                Oops, I think you meant, return null. ;P

                xacc.ide - now with TabsToSpaces support
                IronScheme - 1.0 alpha 3 out now

                P 1 Reply Last reply
                0
                • L leppie

                  PIEBALDconsult wrote:

                  // Ignore Exception

                  Oops, I think you meant, return null. ;P

                  xacc.ide - now with TabsToSpaces support
                  IronScheme - 1.0 alpha 3 out now

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

                  Nah, actually I should have had several instances of that construct, but I didn't want to take up much space

                  try { statement } catch{}
                  try { statement } catch{}
                  try { statement } catch{}
                  try { statement } catch{}
                  ...

                  1 Reply Last reply
                  0
                  • M MarkB777

                    "You'll **catch** on soon enough" :D.

                    Mark Brock Click here to view my blog

                    Z Offline
                    Z Offline
                    zildjohn01
                    wrote on last edited by
                    #15

                    ooh that's bad haha

                    1 Reply Last reply
                    0
                    • J jamie550

                      Is there a reason for this appearing all over the code???

                      try
                      {
                      if (something is wrong)
                      throw new exceptionaboutwhateveriswring();
                      //If nothing was wrong
                      ...
                      ...
                      ...
                      continue work
                      }
                      catch (whatever exception was just thrown)
                      {
                      Console.WriteLine(information about the error);
                      }

                      M Offline
                      M Offline
                      Mr PoorEnglish
                      wrote on last edited by
                      #16

                      never heard about this? :laugh:

                      1 Reply Last reply
                      0
                      • L Luc Pattyn

                        Hi, that is a very clever piece of code. The normal approach:

                        if (!something\_is\_wrong) {
                            // ... do some more
                        } else {
                            // ... show some error message
                        }
                        

                        has several shortcomings: 1. the tests use negative statements, so they are error prone. 2. the error messages do not include class names and line numbers automatically 3. problems don't get encapsulated in objects 4. it disregards the exception trapping functionality available in Visual Studio So basically it is old style, and against all modern OO principles. :)

                        Luc Pattyn [Forum Guidelines] [My Articles]


                        This month's tips: - before you ask a question here, search CodeProject, then Google; - the quality and detail of your question reflects on the effectiveness of the help you are likely to get; - use PRE tags to preserve formatting when showing multi-line code snippets.


                        A Offline
                        A Offline
                        AJGermano
                        wrote on last edited by
                        #17

                        This is a function of mine, could I get a critique on this? The reason for it being there is because exceptions coming out of the lower level library were not very descriptive or helpful to the guy trying to understand where the config was screwed so this layer was added to get some extra info into the exceptions that were coming up if files were missing and so on. Public Shared Function GetInt(ByVal iniFile As String, ByVal sectionName As String, ByVal keyName As String) As Integer Dim i As Integer Dim ConfigFile As IniConfigSource Dim ConfigSection As IConfig Try 'check file exists If (Not System.IO.File.Exists(iniFile)) Then Throw New Exception("Config file does not exist: " & iniFile) End If 'Access the file ConfigFile = New IniConfigSource(iniFile) 'Get section ConfigSection = ConfigFile.Configs(sectionName) 'check section exists If (IsNothing(ConfigSection)) Then Throw New Exception("Config section does not exist: " & iniFile & vbTab & sectionName) End If 'get key and check it is a valid value Try i = ConfigSection.GetInt(keyName) Catch ex As Exception Throw New Exception("Exception attempting to access integer key: " & iniFile & vbTab & sectionName & vbTab & keyName) End Try Return i Catch ex As Exception 'Exceptions come in here Throw ex End Try End Function

                        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