[Gambas-user] Error trapping problem

neil lewis neil at ...233...
Fri Feb 4 15:44:16 CET 2005


Thank you Benoit. I very much appreciate your comments.

I only tried using the external program when I couldn't get any error 
response using Picture and I wasn't at all sure that the error would be 
propagated.
Thanks anyway for steering me away from that idea. I'll try your 
suggestion of using the Load method and see if it helps.

I did also think about passing the output from the ImageMagick function 
back to Gambas so that I could check the contents of the string.
At least that way I could identify whether the file was of a suitable 
type without actually raising an error.

I know I could just check the file extension, but I don't want to go 
that way since Linux doesn't insist on them and I'd rather not impose 
the need for an extension onto the user.

Regards,

Neil Lewis

I'll give that a try.
Benoit Minisini wrote:

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





More information about the User mailing list