The variable e
doesn't become 2. You can act on e.message
, which will be 2 for a badly formed statement. In this case, not only is it not finding the file, but the search rectangle isn't defined since the variables aren't defined. So it doesn't necessarily mean only that the file isn't found.
Another issue is that you don't want to use Throw
here. Throw is what you would use to generate an error to be caught, not to display it. This is closer to what you want:
Code: Select all
ImageSearch, OutputVarX, OutputVarY, X1, Y1, X2, Y2, ImageFile
If (e.message = 2)
MsgBox "File not found."
MsgBox "Image not found."
However, another issue with that is that you're not going to get a message if you have a valid statement (good search rectangle and file name) but just can't find the file because not being able to find the file is not considered a run-time error. It's just one of the two expected outcomes of a valid search, so it won't catch anything. Try out the above code with a valid rectangle and an image file that it can find. Even if it doesn't find the image, it won't show any MsgBox.
See examples in the Try