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. How not to catch the exception

How not to catch the exception

Scheduled Pinned Locked Moved The Weird and The Wonderful
rubyannouncement
7 Posts 5 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.
  • F Offline
    F Offline
    feeza_n3n
    wrote on last edited by
    #1

    While looking into some production issues and after much looking into the few functions that span over 700-1000 lines, I stumbled upon the root cause. Oh my what a priceless gem!

    private static int somefunction(some params)
    {
    int iKey = -1;
    try
    {
    //codes transaction
    }
    catch (SqlException ex)
    {
    return iKey;
    }
    catch (Exception ex)
    {
    return iKey;
    }
    finally
    {
    //release or closed whatever
    }

      return iKey;
    

    }

    M J G 3 Replies Last reply
    0
    • F feeza_n3n

      While looking into some production issues and after much looking into the few functions that span over 700-1000 lines, I stumbled upon the root cause. Oh my what a priceless gem!

      private static int somefunction(some params)
      {
      int iKey = -1;
      try
      {
      //codes transaction
      }
      catch (SqlException ex)
      {
      return iKey;
      }
      catch (Exception ex)
      {
      return iKey;
      }
      finally
      {
      //release or closed whatever
      }

        return iKey;
      

      }

      M Offline
      M Offline
      Mohammed Hameed
      wrote on last edited by
      #2

      What a 'crazy code' it is... :omg: Compiler shouldn't have allowed return statements in catch :-D

      Understand SOLID! Believe SOLID! Try SOLID! Do implement live SOLID; your Code base becomes Rock SOLID!!! http://www.codeproject.com/Articles/593751/Code-Review-Checklist-and-Guidelines-for-Csharp-De

      J 1 Reply Last reply
      0
      • F feeza_n3n

        While looking into some production issues and after much looking into the few functions that span over 700-1000 lines, I stumbled upon the root cause. Oh my what a priceless gem!

        private static int somefunction(some params)
        {
        int iKey = -1;
        try
        {
        //codes transaction
        }
        catch (SqlException ex)
        {
        return iKey;
        }
        catch (Exception ex)
        {
        return iKey;
        }
        finally
        {
        //release or closed whatever
        }

          return iKey;
        

        }

        J Offline
        J Offline
        jim lahey
        wrote on last edited by
        #3

        I battle against these every day, my sympathies.

        1 Reply Last reply
        0
        • M Mohammed Hameed

          What a 'crazy code' it is... :omg: Compiler shouldn't have allowed return statements in catch :-D

          Understand SOLID! Believe SOLID! Try SOLID! Do implement live SOLID; your Code base becomes Rock SOLID!!! http://www.codeproject.com/Articles/593751/Code-Review-Checklist-and-Guidelines-for-Csharp-De

          J Offline
          J Offline
          jim lahey
          wrote on last edited by
          #4

          Developers who would like to keep their jobs writing production code should have a clue about exception handling.

          1 Reply Last reply
          0
          • F feeza_n3n

            While looking into some production issues and after much looking into the few functions that span over 700-1000 lines, I stumbled upon the root cause. Oh my what a priceless gem!

            private static int somefunction(some params)
            {
            int iKey = -1;
            try
            {
            //codes transaction
            }
            catch (SqlException ex)
            {
            return iKey;
            }
            catch (Exception ex)
            {
            return iKey;
            }
            finally
            {
            //release or closed whatever
            }

              return iKey;
            

            }

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

            I think he missed "return iKey" in the finally clause :^)

            Richard DeemingR 1 Reply Last reply
            0
            • G Gaston Verelst

              I think he missed "return iKey" in the finally clause :^)

              Richard DeemingR Offline
              Richard DeemingR Offline
              Richard Deeming
              wrote on last edited by
              #6

              If it's C#, you can't have a return in a finally clause.


              "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

              "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

              G 1 Reply Last reply
              0
              • Richard DeemingR Richard Deeming

                If it's C#, you can't have a return in a finally clause.


                "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

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

                Good "catch" !

                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