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. Best use of exception handling

Best use of exception handling

Scheduled Pinned Locked Moved The Weird and The Wonderful
ruby
15 Posts 14 Posters 1 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.
  • M MalikRizwan

    here is another gem by my colleague. I believe he was drunk when he wrote this as I don't think he would do this in senses.

    Page executingPage = null;
    try
    {
    executingPage = HttpContext.Current.Handler as Page;
    }
    catch(InvalidCastException ex)
    {
    executingPage = HttpContext.Current.Handler as Page;
    }

    **

    R A M

    **

    C Offline
    C Offline
    Chris Meech
    wrote on last edited by
    #4

    If at first you don't succeed, try, try, try throw, throw, throw again. Or something like that. :)

    Chris Meech I am Canadian. [heard in a local bar] In theory there is no difference between theory and practice. In practice there is. [Yogi Berra]

    1 Reply Last reply
    0
    • M MalikRizwan

      here is another gem by my colleague. I believe he was drunk when he wrote this as I don't think he would do this in senses.

      Page executingPage = null;
      try
      {
      executingPage = HttpContext.Current.Handler as Page;
      }
      catch(InvalidCastException ex)
      {
      executingPage = HttpContext.Current.Handler as Page;
      }

      **

      R A M

      **

      M Offline
      M Offline
      Megidolaon
      wrote on last edited by
      #5

      :doh: :sigh: :(( In that order.

      1 Reply Last reply
      0
      • B BillW33

        I know that there are a number of programers that don't understand proper Exception Handling, but this one is really bad. Maybe he was thinking that he should retry? Even then it is not done properly. :sigh:

        Just because the code works, it doesn't mean that it is good code.

        M Offline
        M Offline
        MalikRizwan
        wrote on last edited by
        #6

        :laugh: yeahhh.. it won't go in catch block ever.

        **

        R A M

        **

        1 Reply Last reply
        0
        • M MalikRizwan

          here is another gem by my colleague. I believe he was drunk when he wrote this as I don't think he would do this in senses.

          Page executingPage = null;
          try
          {
          executingPage = HttpContext.Current.Handler as Page;
          }
          catch(InvalidCastException ex)
          {
          executingPage = HttpContext.Current.Handler as Page;
          }

          **

          R A M

          **

          S Offline
          S Offline
          Sauro Viti
          wrote on last edited by
          #7

          I have an improved version:

          Page executingPage = null;
          while (true)
          {
          try
          {
          executingPage = HttpContext.Current.Handler as Page;
          break;
          }
          catch (InvalidCastException ex)
          {
          continue;
          }
          }

          ;P :~

          A R 2 Replies Last reply
          0
          • S Sauro Viti

            I have an improved version:

            Page executingPage = null;
            while (true)
            {
            try
            {
            executingPage = HttpContext.Current.Handler as Page;
            break;
            }
            catch (InvalidCastException ex)
            {
            continue;
            }
            }

            ;P :~

            A Offline
            A Offline
            Adriaan Davel
            wrote on last edited by
            #8

            Yep, this should work MUCH better

            ____________________________________________________________ Be brave little warrior, be VERY brave

            1 Reply Last reply
            0
            • M MalikRizwan

              here is another gem by my colleague. I believe he was drunk when he wrote this as I don't think he would do this in senses.

              Page executingPage = null;
              try
              {
              executingPage = HttpContext.Current.Handler as Page;
              }
              catch(InvalidCastException ex)
              {
              executingPage = HttpContext.Current.Handler as Page;
              }

              **

              R A M

              **

              V Offline
              V Offline
              Vimalsoft Pty Ltd
              wrote on last edited by
              #9

              lol then what was the use of the variable "ex" he simple don't understand exception handling

              Vuyiswa Maseko, Spoted in Daniweb-- Sorry to rant. I hate websites. They are just wierd. They don't behave like normal code. C#/VB.NET/ASP.NET/SQL7/2000/2005/2008 http://www.vuyiswamaseko.com vuyiswa@its.co.za http://www.itsabacus.co.za/itsabacus/

              1 Reply Last reply
              0
              • M MalikRizwan

                here is another gem by my colleague. I believe he was drunk when he wrote this as I don't think he would do this in senses.

                Page executingPage = null;
                try
                {
                executingPage = HttpContext.Current.Handler as Page;
                }
                catch(InvalidCastException ex)
                {
                executingPage = HttpContext.Current.Handler as Page;
                }

                **

                R A M

                **

                J Offline
                J Offline
                Jonas Hammarberg
                wrote on last edited by
                #10

                DWC - (Zero tolerance for) drunk while coding...

                1 Reply Last reply
                0
                • M MalikRizwan

                  here is another gem by my colleague. I believe he was drunk when he wrote this as I don't think he would do this in senses.

                  Page executingPage = null;
                  try
                  {
                  executingPage = HttpContext.Current.Handler as Page;
                  }
                  catch(InvalidCastException ex)
                  {
                  executingPage = HttpContext.Current.Handler as Page;
                  }

                  **

                  R A M

                  **

                  M Offline
                  M Offline
                  Mel Padden
                  wrote on last edited by
                  #11

                  That's GOT to be a DWC!! :laugh:

                  Smokie, this is not 'Nam. This is bowling. There are rules. www.geticeberg.com

                  V 1 Reply Last reply
                  0
                  • M MalikRizwan

                    here is another gem by my colleague. I believe he was drunk when he wrote this as I don't think he would do this in senses.

                    Page executingPage = null;
                    try
                    {
                    executingPage = HttpContext.Current.Handler as Page;
                    }
                    catch(InvalidCastException ex)
                    {
                    executingPage = HttpContext.Current.Handler as Page;
                    }

                    **

                    R A M

                    **

                    T Offline
                    T Offline
                    T Jenniges
                    wrote on last edited by
                    #12

                    I once fixed something similar that was coded by a newbie, it went something like this: private void HandleException(Exception ex) { try { ... Code to handle exception that would always throw an exception ... Can't recall exactly what it was since it was 3 years ago } catch (Exception ex) { HandleException(ex); } } The function would recursively call itself and cause a stack overflow exception.

                    1 Reply Last reply
                    0
                    • M Mel Padden

                      That's GOT to be a DWC!! :laugh:

                      Smokie, this is not 'Nam. This is bowling. There are rules. www.geticeberg.com

                      V Offline
                      V Offline
                      Vercas
                      wrote on last edited by
                      #13

                      I'm always more productive when drunk. ;P (Off-topic) But yeah, he was probably drunk.

                      1 Reply Last reply
                      0
                      • M MalikRizwan

                        here is another gem by my colleague. I believe he was drunk when he wrote this as I don't think he would do this in senses.

                        Page executingPage = null;
                        try
                        {
                        executingPage = HttpContext.Current.Handler as Page;
                        }
                        catch(InvalidCastException ex)
                        {
                        executingPage = HttpContext.Current.Handler as Page;
                        }

                        **

                        R A M

                        **

                        K Offline
                        K Offline
                        kxal
                        wrote on last edited by
                        #14

                        I think it is a waste of code

                        1 Reply Last reply
                        0
                        • S Sauro Viti

                          I have an improved version:

                          Page executingPage = null;
                          while (true)
                          {
                          try
                          {
                          executingPage = HttpContext.Current.Handler as Page;
                          break;
                          }
                          catch (InvalidCastException ex)
                          {
                          continue;
                          }
                          }

                          ;P :~

                          R Offline
                          R Offline
                          richard_k
                          wrote on last edited by
                          #15

                          LOL!!! Oh man.. you just made my week.

                          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