[Gambas-user] Error trapping problem

neil lewis gibsonsphoto at ...247...
Thu Feb 3 17:39:39 CET 2005


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.


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
       .
       .

Any ideas how else I could detect non-image file types and get Gambas to
detect the error?

Neil Lewis.






More information about the User mailing list