Results 1 to 4 of 4

Thread: Errors

  1. #1

    Thread Starter
    Fanatic Member Nove's Avatar
    Join Date
    Jul 2004
    Posts
    736

    Errors

    Hi.
    From a "good code" standpoint, is it ok to just skip over errors if it provides for less if statements? Here's an example in pseudocode.

    VB Code:
    1. On Error Resume Next
    2. Dim Path as String
    3. Path = ""
    4. 'draw a circle
    5. picBox.DrawCircle
    6. 'if picture for better circle is present, load it, otherwise just skip
    7. 'If Path <> "" Then
    8. picBox.LoadPicture(Path)
    9. 'End if

    As you can see, I can either skip right over the load error and I have my already drawn circle to back me up, or I can go through a slightly longer method of checking to see if an error will come up or not. In your opinion, is it ok to just skip the error like this?

  2. #2
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Re: Errors

    I often take that approach, to treat errors as exceptions and just ignore them if they happen. IMHO there is nothing wrong with that, in a way you've already handled the error by drawing the circle first.

  3. #3
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758

    Re: Errors

    LoadPicture("") does not cause an error but will clear the picturebox, so you would need an If Path <> "" statement anyways.

    I do understand what you are asking. However, Resume Next ignores ALL unexpected errors. Wouldn't you want to know if the Path were valid or that the file which was chosen is a valid image file (and not say a Word Document). I guess, it would depend on how the Path variable is set and the nature of the application.

  4. #4
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Re: Errors

    Quote Originally Posted by brucevde
    Resume Next ignores ALL unexpected errors. Wouldn't you want to know if the Path were valid or that the file which was chosen is a valid image file (and not say a Word Document).
    As I understood it the whole point was that he didn't care why the image wasn't loaded just that if it wasn't he would have a circle in the picture box anyway. But it's true that he needs to check for an empty string (I didn't read the comments in his code closely enough).

Posting Permissions

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



Click Here to Expand Forum to Full Width