[Gambas-user] Error trapping problem
Benoit Minisini
gambas at ...1...
Fri Feb 4 15:08:01 CET 2005
On Thursday 03 February 2005 17:39, neil lewis wrote:
> Hi All,
>
> I've been using Gambas for a while now, and my image processing project
> has grown to a usable state. I'm now trying to add extra convenience and
> error trapping features.
>
> One of these new features is a subroutine which loads multiple image
> file names into an array using Dir and For Each. Later, these are used
> to fetch the actual images for processing.
> The user specifies the source folder for the image files and a pattern
> to match, which can be as general as "*". Some folders may contain
> non-image files, eg text or sound.
> I'd like to be able to check for non-image file names being accidentally
> added to the array using Try but can't seem to get it to work.
> I've tried two methods so far. Gambas did not detect the error in either
> case.
>
> Here is what I did:
>
> The sub uses local variables; DIM temppic as Picture
> DIM temppath as
> String 'used to hold the full path and file name for the
> file being checked
>
> version 1
> TRY temppic = Picture[temppath]
> 'test to see if the file identified by the path can be made into a
> picture
>
> With or without the TRY in place, Gambas makes no fuss, even when given
> a text file.
Don't use the cache feature of the Picture class. Use the Load method instead.
This method must return an error if the file can't be interpreted as an image
file, or it is a bug in Gambas :-)
>
>
> version 2
> TRY EXEC ["identify", "-format", "%m", temppath] 'test
> to see if it's an image using ImageMagick to identify the image type
>
> With or without the TRY in place, ImageMagick displays a console error
> message for non-image file types, but Gambas does not see the error.
>
> In each case, I followed the above with
>
> IF ERROR THEN
> 'if not, report the error and continue
> msg(8)
> 'print an error message to the programs display
> CONTINUE
> 'carry on with next file
> ELSE
> .
> 'do the other stuff I need done with
> the valid image files
> .
> .
You are mixe-up! An external program that fails does not mean that Gambas
couldn't execute it. So EXEC always succeeds, even if the executed program
returns an error. You must check the return value.
Regards,
--
Benoit Minisini
mailto:gambas at ...1...
More information about the User
mailing list