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. The Lounge
  3. Try statements in vb laziness?

Try statements in vb laziness?

Scheduled Pinned Locked Moved The Lounge
csharpquestion
33 Posts 14 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.
  • G Offline
    G Offline
    GregScott
    wrote on last edited by
    #1

    is using try statements in vb.net bad programing practice.

    P D C K S 6 Replies Last reply
    0
    • G GregScott

      is using try statements in vb.net bad programing practice.

      D Offline
      D Offline
      Duncan Edwards Jones
      wrote on last edited by
      #2

      No. But using exception handling instead of parameter/environment state validation is.

      '--8<------------------------ Ex Datis: Duncan Jones Merrion Computing Ltd

      1 Reply Last reply
      0
      • G GregScott

        is using try statements in vb.net bad programing practice.

        P Offline
        P Offline
        Paul Conrad
        wrote on last edited by
        #3

        GregScott wrote:

        is using try statements in vb.net bad programing practice

        Depends on who you talk to and their thoughts on exception handling...

        L 1 Reply Last reply
        0
        • G GregScott

          is using try statements in vb.net bad programing practice.

          C Offline
          C Offline
          Colin Angus Mackay
          wrote on last edited by
          #4

          Using Try Catch Finally can be very good programming practice (exceptionally good practice, some might say) if used correctly.


          Upcoming events: * Glasgow: SQL Server 2005 - XML and XML Query Plans, Mock Objects, SQL Server Reporting Services... Never write for other people. Write for yourself, because you have a passion for it. -- Marc Clifton My website

          J L 2 Replies Last reply
          0
          • G GregScott

            is using try statements in vb.net bad programing practice.

            K Offline
            K Offline
            Kevin McFarlane
            wrote on last edited by
            #5

            No.

            Kevin

            1 Reply Last reply
            0
            • G GregScott

              is using try statements in vb.net bad programing practice.

              S Offline
              S Offline
              Shog9 0
              wrote on last edited by
              #6

              No, just the VB part. :rolleyes:

              ----

              i hope you are feeling sleepy for people not calling you by the same.

              --BarnaKol on abusive words

              F M 2 Replies Last reply
              0
              • S Shog9 0

                No, just the VB part. :rolleyes:

                ----

                i hope you are feeling sleepy for people not calling you by the same.

                --BarnaKol on abusive words

                F Offline
                F Offline
                Fred_Smith
                wrote on last edited by
                #7

                Shog9 wrote:

                No, just the VB part

                You just couldn't resist, could you? :) I've got a headache today X| , so you're spared... (And no, it isn't because I've been....) Fred

                S 1 Reply Last reply
                0
                • S Shog9 0

                  No, just the VB part. :rolleyes:

                  ----

                  i hope you are feeling sleepy for people not calling you by the same.

                  --BarnaKol on abusive words

                  M Offline
                  M Offline
                  Marcus J Smith
                  wrote on last edited by
                  #8

                  Why I oughta! ;P


                  CleaKO

                  "Now, a man would have opened both gates, driven through and not bothered to close either gate." - Marc Clifton (The Lounge)

                  S 1 Reply Last reply
                  0
                  • F Fred_Smith

                    Shog9 wrote:

                    No, just the VB part

                    You just couldn't resist, could you? :) I've got a headache today X| , so you're spared... (And no, it isn't because I've been....) Fred

                    S Offline
                    S Offline
                    Shog9 0
                    wrote on last edited by
                    #9

                    Fred_Smith wrote:

                    You just couldn't resist, could you?

                    Nope. ;) I've been reviewing VB.NET code from a consultant. He's working on porting a VB6 library to VB.NET, and cleaning it up along the way. The original code was... really awful, so i have a lot of sympathy for him... but still, i would never ask for a review of code that looked like this. I tell ya, every time my attitude towards VB starts to soften, i end up seeing VB code, and then all the bitterness just comes rushing back. And yeah, just about every method has Try ... Catch \ Throw \ End Try wrapped around it. :doh:

                    ----

                    i hope you are feeling sleepy for people not calling you by the same.

                    --BarnaKol on abusive words

                    M F K 3 Replies Last reply
                    0
                    • M Marcus J Smith

                      Why I oughta! ;P


                      CleaKO

                      "Now, a man would have opened both gates, driven through and not bothered to close either gate." - Marc Clifton (The Lounge)

                      S Offline
                      S Offline
                      Shog9 0
                      wrote on last edited by
                      #10

                      CleaKO wrote:

                      Why I oughta

                      ...learn a real language? I agree! ;P (sorry, that was just too tempting...)

                      ----

                      i hope you are feeling sleepy for people not calling you by the same.

                      --BarnaKol on abusive words

                      1 Reply Last reply
                      0
                      • S Shog9 0

                        Fred_Smith wrote:

                        You just couldn't resist, could you?

                        Nope. ;) I've been reviewing VB.NET code from a consultant. He's working on porting a VB6 library to VB.NET, and cleaning it up along the way. The original code was... really awful, so i have a lot of sympathy for him... but still, i would never ask for a review of code that looked like this. I tell ya, every time my attitude towards VB starts to soften, i end up seeing VB code, and then all the bitterness just comes rushing back. And yeah, just about every method has Try ... Catch \ Throw \ End Try wrapped around it. :doh:

                        ----

                        i hope you are feeling sleepy for people not calling you by the same.

                        --BarnaKol on abusive words

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

                        Just out of curiosity what is wrong with Implementing a Try / Catch / End Try in each method?

                        Mike Lasseter

                        S 1 Reply Last reply
                        0
                        • S Shog9 0

                          Fred_Smith wrote:

                          You just couldn't resist, could you?

                          Nope. ;) I've been reviewing VB.NET code from a consultant. He's working on porting a VB6 library to VB.NET, and cleaning it up along the way. The original code was... really awful, so i have a lot of sympathy for him... but still, i would never ask for a review of code that looked like this. I tell ya, every time my attitude towards VB starts to soften, i end up seeing VB code, and then all the bitterness just comes rushing back. And yeah, just about every method has Try ... Catch \ Throw \ End Try wrapped around it. :doh:

                          ----

                          i hope you are feeling sleepy for people not calling you by the same.

                          --BarnaKol on abusive words

                          F Offline
                          F Offline
                          Fred_Smith
                          wrote on last edited by
                          #12

                          I refuse to port code - even my own! It's quicker, easier, (and therefore cheaper) and a whole lot more enjoyable, to start over... Classic ASP to ASP.NET? Not on your life... Fred

                          S N 2 Replies Last reply
                          0
                          • M mr_lasseter

                            Just out of curiosity what is wrong with Implementing a Try / Catch / End Try in each method?

                            Mike Lasseter

                            S Offline
                            S Offline
                            Shog9 0
                            wrote on last edited by
                            #13

                            Two things:

                            1. It is laziness - rather than identifying the specific exceptions that might be thrown and handling just the ones that can actually be handled effectively, all exceptions are caught... and, not handled.
                            2. Blindly re-throwing exceptions just makes debugging harder. And since the low-level code isn't doing anything to interpret specific exceptions, high-level code is forced into the same pattern of blindly catching all exceptions.

                            ----

                            i hope you are feeling sleepy for people not calling you by the same.

                            --BarnaKol on abusive words

                            M 1 Reply Last reply
                            0
                            • F Fred_Smith

                              I refuse to port code - even my own! It's quicker, easier, (and therefore cheaper) and a whole lot more enjoyable, to start over... Classic ASP to ASP.NET? Not on your life... Fred

                              S Offline
                              S Offline
                              Shog9 0
                              wrote on last edited by
                              #14

                              Well, the original library was in rough shape, nearly unmaintainable, and yet crucial to the operation of the program. I encouraged the developer to re-use as little of the actual code as possible, but i guess he thought it would be quicker to try it anyway. For me, the first shock came with seeing that FileOpen is still even supported in VB.NET... :wtf:

                              ----

                              i hope you are feeling sleepy for people not calling you by the same.

                              --BarnaKol on abusive words

                              1 Reply Last reply
                              0
                              • G GregScott

                                is using try statements in vb.net bad programing practice.

                                P Offline
                                P Offline
                                Paul Brower
                                wrote on last edited by
                                #15

                                using try statements in vb.net bad programing practice.

                                1 Reply Last reply
                                0
                                • S Shog9 0

                                  Two things:

                                  1. It is laziness - rather than identifying the specific exceptions that might be thrown and handling just the ones that can actually be handled effectively, all exceptions are caught... and, not handled.
                                  2. Blindly re-throwing exceptions just makes debugging harder. And since the low-level code isn't doing anything to interpret specific exceptions, high-level code is forced into the same pattern of blindly catching all exceptions.

                                  ----

                                  i hope you are feeling sleepy for people not calling you by the same.

                                  --BarnaKol on abusive words

                                  M Offline
                                  M Offline
                                  mr_lasseter
                                  wrote on last edited by
                                  #16

                                  I would agree with you in your business layer you should not handle any exceptions that you can't fix. But in the UI I think it is a different story, I would think in the UI you want to catch all exceptions so you could: 1. Log the exception 2. Display the error to the user without the application exiting abruptly.

                                  Mike Lasseter

                                  S L D 3 Replies Last reply
                                  0
                                  • P Paul Conrad

                                    GregScott wrote:

                                    is using try statements in vb.net bad programing practice

                                    Depends on who you talk to and their thoughts on exception handling...

                                    L Offline
                                    L Offline
                                    led mike
                                    wrote on last edited by
                                    #17

                                    Paul Conrad wrote:

                                    Depends on who you talk to and their thoughts on exception handling...

                                    No it doesn't and neither does gravity.

                                    led mike

                                    1 Reply Last reply
                                    0
                                    • M mr_lasseter

                                      I would agree with you in your business layer you should not handle any exceptions that you can't fix. But in the UI I think it is a different story, I would think in the UI you want to catch all exceptions so you could: 1. Log the exception 2. Display the error to the user without the application exiting abruptly.

                                      Mike Lasseter

                                      S Offline
                                      S Offline
                                      Shog9 0
                                      wrote on last edited by
                                      #18

                                      Even in the UI, i'm a bit uncomfortable catching exceptions that can't be reasonably handled... but i'll allow that it might be useful in a few specific cases. Of course, you wouldn't re-throw the exception in those cases either.

                                      ----

                                      i hope you are feeling sleepy for people not calling you by the same.

                                      --BarnaKol on abusive words

                                      1 Reply Last reply
                                      0
                                      • M mr_lasseter

                                        I would agree with you in your business layer you should not handle any exceptions that you can't fix. But in the UI I think it is a different story, I would think in the UI you want to catch all exceptions so you could: 1. Log the exception 2. Display the error to the user without the application exiting abruptly.

                                        Mike Lasseter

                                        L Offline
                                        L Offline
                                        led mike
                                        wrote on last edited by
                                        #19

                                        mr_lasseter wrote:

                                        But in the UI I think it is a different story, I would think in the UI you want to catch all exceptions so you could:

                                        Not really. In general you don't want anything but rendering logic and user interface event handling in the presentation layer.

                                        led mike

                                        M 1 Reply Last reply
                                        0
                                        • L led mike

                                          mr_lasseter wrote:

                                          But in the UI I think it is a different story, I would think in the UI you want to catch all exceptions so you could:

                                          Not really. In general you don't want anything but rendering logic and user interface event handling in the presentation layer.

                                          led mike

                                          M Offline
                                          M Offline
                                          mr_lasseter
                                          wrote on last edited by
                                          #20

                                          What is it that you mean by user interface event handling? I would think you call the following event handling and in the following if the Load method failed (due to the database being unavailable) wouldn't you want to inform the user the the database is down? Private Sub MyButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyButton.Click BindingSource.DataSource = BusinessObject.Load() End Sub

                                          Mike Lasseter

                                          L 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