Error Handling

The classes graphic importer, graphic exporter, movie importer and movie editor all contain two different error codes. These error codes are accessible as properties of the classes. For the class graphic exporter the names of the properties are export component error, and export last operation error. For all the other classes the names of the properties are component error and last operation error.

Unless otherwise specified when referring to component error and last operation error I am also talking about export component error and export last operation error.

Last operation error indicates that the last operation failed or would have failed if attempted. For example the only graphic importer or exporter that understands the quality setting is jpeg. If you attempt to set the quality setting for any other graphic importer or exporter then the last operation error will be set to an error code, but the component error will be still be set to 0 (0 means no error) . In the case of a graphic importer, it will still be able to draw, and a graphic exporter will still be able to create an image file.

The component error usually indicates that something more serious has happened. It is usually set if a graphic or movie importer is created from a file that is not a image or movie. In this case the graphic or movie importer object is created but the component error is set and the only thing you can do is to close the graphic or movie importer. Closing a graphic or movie object that has the component error set is almost the only thing you can do.

tell application "iMagine Photo"
 
set thisFile to choose file with prompt "Choose any non image file: "
 
set thisImporter to import graphic thisFile
  
set componentError to the component error of thisImporter
  
if componentError is not equal to 0 then
    --
an error occured the only thing we can do is close the importer
    
close thisImporter
    --
return after closing the importer it is usually necessary to return or exit repeat
    
display dialog "Component Error is: " & componentError
    
return
  
end if
  --
in this simple script we have to close the graphic importer anyway since we aren't do anything with it.
  
close thisImporter
end tell

In rare situations you know why the component error was set and that what ever the problem was has been fixed. In that case, the only other operation that you can do to an object which has the component error set is to clear the error. You can do that by setting the component error to 0, but that is no gaurantee that the component will work after that.

  set the component error of thisImporter to 0

For a graphic exporter object changing the export file type will clear the export component error.