+ Reply to Thread
Results 1 to 79 of 79

Do's and Don'ts So Others Won't

Hybrid View

  1. #1
    Valued Forum Contributor blane245's Avatar
    Join Date
    02-20-2009
    Location
    Melbourne, FL
    MS-Off Ver
    Excel 2010
    Posts
    649

    Re: Do's and Don'ts So Others Won't

    Quote Originally Posted by romperstomper View Post
    You mean you don't use error handling blocks, you just use On Error Resume Next?
    Correct. In effect, error handling blocks are in line with the code. I will use Exit Sub in the block after setting appropraite error flags, if necessary.

    I know this is a style thing. I find it easier to assure myself that I have handed error conditions by leaving the hanlding block near the error.

    If VBA had try...catch like other languages, I would prefer it. On Error Resume Next the closest I can get.
    Bob
    Click my star if my answer helped you. Mark the thread as [SOLVED] if it has been.

  2. #2
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    22,052

    Re: Do's and Don'ts So Others Won't

    Quote Originally Posted by blane245 View Post
    If VBA had try...catch like other languages, I would prefer it. On Error Resume Next the closest I can get.
    I would have said that on error goto label was closer to Try...Catch, but hey, it's your code.

    Of course that assumes you can predict every single error...
    Everyone who confuses correlation and causation ends up dead.

  3. #3
    Valued Forum Contributor blane245's Avatar
    Join Date
    02-20-2009
    Location
    Melbourne, FL
    MS-Off Ver
    Excel 2010
    Posts
    649

    Re: Do's and Don'ts So Others Won't

    Quote Originally Posted by romperstomper View Post
    I would have said that on error goto label was closer to Try...Catch, but hey, it's your code.

    Of course that assumes you can predict every single error...
    You are right about goto label being close to try...catch. You got me on that one. I think the goto label method is definately a good way to protect code for any type of unforseen error, though a bit weak in knowing what to do when one of those unforseen errors occur. In general, doing exception handling is like writing a second program inside on the original one.

    Error prediction is an essential part of robust coding. If you are trying to protect against hardware as well as software faults, then there may no other way than to use on error goto label. But in the VBA environment, I am not sure your code will get control on those types of errors. For example, if you have a read failure on a disk drive, will VBA let your code get control of that, or will VBA or Windows trap that error and forget about you.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1