You’re getting that exception on the line that creates the FolderItem, not the line that actually does the saving. Since it isn’t inside the Try block, the exception isn’t caught.
Thanks Eric. Yes, I am capable of doing what you wrote below, but…
No, it is IN the TRY BLOCK.
And the Exception is fired when the debuger runs the SAVE line.
The debug point is in the Save line and the error arise when I click to the Step line, not whan the debug line stop on the Save line. Look at the top of the original post, far above.
I do not inspect carefully what the FolderItem is (it certainly ends with ‘/’ followed by nothing since the file name is… “”. That nothing is my bug (and I do not understand yet why)
I add a If Cover_Name = “” test and add some text: everything is OK (excepted the file name, but at this point, I do not care: search and replace in the Finder = OK, temporary).
Well, if the variable is empty, you’re trying to access Image_FI.Child(“”), which means your saveFile variable stays at the enclosing folder. Then you try to save a picture to a folderitem that points to a folder; this can’t work anyway.
Exactly as I thought, you are not catching the exception that is being raised. A try block will only catch the exceptions you catch. Any other exceptions continue to operation as if the try block didn’t exist. Try the following:
Var saveFile As FolderItem = Image_FI.Child(Cover_Name)
Try
scaledImage.Save(saveFile, Picture.Formats.PNG)
Catch err As IOException
// Gérer l'erreur
System.DebugLog "Impossible d’enregistrer l’image."
Catch err As UnsupportedFormatException
// Format not supported
System.DebugLog "Unsupported format exception has occurred."
End Try
For example:
Try
// This try block will behave as if it didn't even exist
// as it doesn't catch anything
scaledImage.Save(saveFile, Picture.Formats.PNG)
End Try
This should be all you need to figure it out. Cover_Name is empty. You probably intended to set Cover_Name to File_FI.Name at some point prior. As others have explained, you’re trying to get a FolderItem to Image_FI.Child("") which will not be valid. Your catch block does not catch the exception being thrown because it’s not been coded to.