|
-
Mar 3rd, 2006, 05:03 PM
#1
Thread Starter
Fanatic Member
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:
On Error Resume Next
Dim Path as String
Path = ""
'draw a circle
picBox.DrawCircle
'if picture for better circle is present, load it, otherwise just skip
'If Path <> "" Then
picBox.LoadPicture(Path)
'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?
-
Mar 3rd, 2006, 05:20 PM
#2
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.
-
Mar 3rd, 2006, 05:40 PM
#3
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.
-
Mar 3rd, 2006, 06:11 PM
#4
Re: Errors
 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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|