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. Catches win matches... they say

Catches win matches... they say

Scheduled Pinned Locked Moved The Weird and The Wonderful
11 Posts 9 Posters 2 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.
  • T Offline
    T Offline
    tumbledDown2earth
    wrote on last edited by
    #1

    Found this in a would be production code today ...

    public bool InitializeApp()
    {
    // Log

    bool bStatus = false;
    try
    {
        // step 2 :
        try
        {
            DoStep2();
        }
        catch (Exception ex)
        {
            // Log ex
        }
    
        // step 3 :
        try
        {
            DoStep3();
        }
        catch (Exception ex)
        {
            // Log ex
        }
    
        // step 4 :
        try
        {
            DoStep4();
        }
        catch (Exception ex)
        {
            // Log ex
        }
    
        // step 5 :
        try
        {
            DoStep5();
        }
        catch (Exception ex)
        {
            // Log ex
        }
    
        // step 6 :
        try
        {
            DoStep6();
        }
        catch (Exception ex)
        {
            // Log ex
        }
    }
    catch (Exception eError)
    {
        // Log -- God knows how can some code get in here -- unless a Log exception throws
    }
    
    return bStatus;
    

    }

    Goes without saying that every DoStep method has a try-catchEverything block with log If I am still missing the point .. its the nested try-catch I am pointing to :laugh:

    P L A B G 6 Replies Last reply
    0
    • T tumbledDown2earth

      Found this in a would be production code today ...

      public bool InitializeApp()
      {
      // Log

      bool bStatus = false;
      try
      {
          // step 2 :
          try
          {
              DoStep2();
          }
          catch (Exception ex)
          {
              // Log ex
          }
      
          // step 3 :
          try
          {
              DoStep3();
          }
          catch (Exception ex)
          {
              // Log ex
          }
      
          // step 4 :
          try
          {
              DoStep4();
          }
          catch (Exception ex)
          {
              // Log ex
          }
      
          // step 5 :
          try
          {
              DoStep5();
          }
          catch (Exception ex)
          {
              // Log ex
          }
      
          // step 6 :
          try
          {
              DoStep6();
          }
          catch (Exception ex)
          {
              // Log ex
          }
      }
      catch (Exception eError)
      {
          // Log -- God knows how can some code get in here -- unless a Log exception throws
      }
      
      return bStatus;
      

      }

      Goes without saying that every DoStep method has a try-catchEverything block with log If I am still missing the point .. its the nested try-catch I am pointing to :laugh:

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

      I've had to do that in certain circumstances. Use the right tool for the right job.

      R 1 Reply Last reply
      0
      • T tumbledDown2earth

        Found this in a would be production code today ...

        public bool InitializeApp()
        {
        // Log

        bool bStatus = false;
        try
        {
            // step 2 :
            try
            {
                DoStep2();
            }
            catch (Exception ex)
            {
                // Log ex
            }
        
            // step 3 :
            try
            {
                DoStep3();
            }
            catch (Exception ex)
            {
                // Log ex
            }
        
            // step 4 :
            try
            {
                DoStep4();
            }
            catch (Exception ex)
            {
                // Log ex
            }
        
            // step 5 :
            try
            {
                DoStep5();
            }
            catch (Exception ex)
            {
                // Log ex
            }
        
            // step 6 :
            try
            {
                DoStep6();
            }
            catch (Exception ex)
            {
                // Log ex
            }
        }
        catch (Exception eError)
        {
            // Log -- God knows how can some code get in here -- unless a Log exception throws
        }
        
        return bStatus;
        

        }

        Goes without saying that every DoStep method has a try-catchEverything block with log If I am still missing the point .. its the nested try-catch I am pointing to :laugh:

        L Offline
        L Offline
        lewax00
        wrote on last edited by
        #3

        It's not that bad, unless each step depends on the previous step completing successfully, in which case there's no reason to run the rest when you know they will fail.

        1 Reply Last reply
        0
        • T tumbledDown2earth

          Found this in a would be production code today ...

          public bool InitializeApp()
          {
          // Log

          bool bStatus = false;
          try
          {
              // step 2 :
              try
              {
                  DoStep2();
              }
              catch (Exception ex)
              {
                  // Log ex
              }
          
              // step 3 :
              try
              {
                  DoStep3();
              }
              catch (Exception ex)
              {
                  // Log ex
              }
          
              // step 4 :
              try
              {
                  DoStep4();
              }
              catch (Exception ex)
              {
                  // Log ex
              }
          
              // step 5 :
              try
              {
                  DoStep5();
              }
              catch (Exception ex)
              {
                  // Log ex
              }
          
              // step 6 :
              try
              {
                  DoStep6();
              }
              catch (Exception ex)
              {
                  // Log ex
              }
          }
          catch (Exception eError)
          {
              // Log -- God knows how can some code get in here -- unless a Log exception throws
          }
          
          return bStatus;
          

          }

          Goes without saying that every DoStep method has a try-catchEverything block with log If I am still missing the point .. its the nested try-catch I am pointing to :laugh:

          A Offline
          A Offline
          AlphaDeltaTheta
          wrote on last edited by
          #4

          Well, I always have an Uncaught Exception Handler. I program mostly in Java and C# and I don't like any hangs or crashes. get an uncaught handler, if at all an exception occurs, (yes... I give heed to LogException too) if is shown as - "POSSIBLE BUG... Please help us to fix it by sending a brief bug report"...

          1 Reply Last reply
          0
          • T tumbledDown2earth

            Found this in a would be production code today ...

            public bool InitializeApp()
            {
            // Log

            bool bStatus = false;
            try
            {
                // step 2 :
                try
                {
                    DoStep2();
                }
                catch (Exception ex)
                {
                    // Log ex
                }
            
                // step 3 :
                try
                {
                    DoStep3();
                }
                catch (Exception ex)
                {
                    // Log ex
                }
            
                // step 4 :
                try
                {
                    DoStep4();
                }
                catch (Exception ex)
                {
                    // Log ex
                }
            
                // step 5 :
                try
                {
                    DoStep5();
                }
                catch (Exception ex)
                {
                    // Log ex
                }
            
                // step 6 :
                try
                {
                    DoStep6();
                }
                catch (Exception ex)
                {
                    // Log ex
                }
            }
            catch (Exception eError)
            {
                // Log -- God knows how can some code get in here -- unless a Log exception throws
            }
            
            return bStatus;
            

            }

            Goes without saying that every DoStep method has a try-catchEverything block with log If I am still missing the point .. its the nested try-catch I am pointing to :laugh:

            B Offline
            B Offline
            Bernhard Hiller
            wrote on last edited by
            #5

            I also like the fact that it will always return false. Did you miss this most important feature? :)

            T 1 Reply Last reply
            0
            • B Bernhard Hiller

              I also like the fact that it will always return false. Did you miss this most important feature? :)

              T Offline
              T Offline
              tumbledDown2earth
              wrote on last edited by
              #6

              :)) good eyes

              1 Reply Last reply
              0
              • P PIEBALDconsult

                I've had to do that in certain circumstances. Use the right tool for the right job.

                R Offline
                R Offline
                Rob Grainger
                wrote on last edited by
                #7

                Can you elaborate? I find it hard to conceive of a situation where that would be necessary, but am willing to be proved wrong.

                "If you don't fail at least 90 percent of the time, you're not aiming high enough." Alan Kay.

                P 1 Reply Last reply
                0
                • R Rob Grainger

                  Can you elaborate? I find it hard to conceive of a situation where that would be necessary, but am willing to be proved wrong.

                  "If you don't fail at least 90 percent of the time, you're not aiming high enough." Alan Kay.

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

                  What came to mind was a Windows Service I wrote a few years back that had to perform a number of related, but not dependent, tasks. An analog that also came to mind was babysitting... the babysitter will have a number of tasks: 0) Check the kid's homework 1) Feed the kid 2) Put the kid to bed A problem in one task doesn't mean you can't perform the others: If the kid doesn't do the homework or has errors, you still feed him. If the kid doesn't eat his vegetables, you still put him to bed. Just log it and continue. If the problem is bad enough, alert the parents, but don't go running out of the house.

                  L 1 Reply Last reply
                  0
                  • P PIEBALDconsult

                    What came to mind was a Windows Service I wrote a few years back that had to perform a number of related, but not dependent, tasks. An analog that also came to mind was babysitting... the babysitter will have a number of tasks: 0) Check the kid's homework 1) Feed the kid 2) Put the kid to bed A problem in one task doesn't mean you can't perform the others: If the kid doesn't do the homework or has errors, you still feed him. If the kid doesn't eat his vegetables, you still put him to bed. Just log it and continue. If the problem is bad enough, alert the parents, but don't go running out of the house.

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

                    Food is a reward for doing the homework. I will be a terrible parent.

                    Greetings - Jacek

                    1 Reply Last reply
                    0
                    • T tumbledDown2earth

                      Found this in a would be production code today ...

                      public bool InitializeApp()
                      {
                      // Log

                      bool bStatus = false;
                      try
                      {
                          // step 2 :
                          try
                          {
                              DoStep2();
                          }
                          catch (Exception ex)
                          {
                              // Log ex
                          }
                      
                          // step 3 :
                          try
                          {
                              DoStep3();
                          }
                          catch (Exception ex)
                          {
                              // Log ex
                          }
                      
                          // step 4 :
                          try
                          {
                              DoStep4();
                          }
                          catch (Exception ex)
                          {
                              // Log ex
                          }
                      
                          // step 5 :
                          try
                          {
                              DoStep5();
                          }
                          catch (Exception ex)
                          {
                              // Log ex
                          }
                      
                          // step 6 :
                          try
                          {
                              DoStep6();
                          }
                          catch (Exception ex)
                          {
                              // Log ex
                          }
                      }
                      catch (Exception eError)
                      {
                          // Log -- God knows how can some code get in here -- unless a Log exception throws
                      }
                      
                      return bStatus;
                      

                      }

                      Goes without saying that every DoStep method has a try-catchEverything block with log If I am still missing the point .. its the nested try-catch I am pointing to :laugh:

                      G Offline
                      G Offline
                      Gaston Verelst
                      wrote on last edited by
                      #10

                      Looks like on error resume next

                      1 Reply Last reply
                      0
                      • T tumbledDown2earth

                        Found this in a would be production code today ...

                        public bool InitializeApp()
                        {
                        // Log

                        bool bStatus = false;
                        try
                        {
                            // step 2 :
                            try
                            {
                                DoStep2();
                            }
                            catch (Exception ex)
                            {
                                // Log ex
                            }
                        
                            // step 3 :
                            try
                            {
                                DoStep3();
                            }
                            catch (Exception ex)
                            {
                                // Log ex
                            }
                        
                            // step 4 :
                            try
                            {
                                DoStep4();
                            }
                            catch (Exception ex)
                            {
                                // Log ex
                            }
                        
                            // step 5 :
                            try
                            {
                                DoStep5();
                            }
                            catch (Exception ex)
                            {
                                // Log ex
                            }
                        
                            // step 6 :
                            try
                            {
                                DoStep6();
                            }
                            catch (Exception ex)
                            {
                                // Log ex
                            }
                        }
                        catch (Exception eError)
                        {
                            // Log -- God knows how can some code get in here -- unless a Log exception throws
                        }
                        
                        return bStatus;
                        

                        }

                        Goes without saying that every DoStep method has a try-catchEverything block with log If I am still missing the point .. its the nested try-catch I am pointing to :laugh:

                        J Offline
                        J Offline
                        jbojarczuk
                        wrote on last edited by
                        #11

                        One use for such a structure would be to fully log the error without having debuging info in the compiled form. If that is the case, then the outer try/catch would be the unnecessary one, not the internal ones.

                        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