try / catch with extenal java packages

I have a code like this

var file = java.io.File(source);
try {
   var workbook = Packages.jxl.Workbook.getWorkbook(file);
}
catch (exception) {
   var msg = "The file is not valid. Please check.";
   plugins.dialogs.showErrorDialog("", msg);
   return;
}

The getWorkbook() method is supposed get an excel file.

If I pass an image file I suppose the catch block should be executed.
But it just throws the normal servoy error dialog.

jxl.read.biff.BiffException: Unable to recognize OLE stream (local_functions_product_importFromExcel, line 11)

Where and when does this happen?

Tested with the latest 3.5 RC and (offcourse as long as teh debugger is off!!!), an error within the try block will be properly catched.

I do not have the library you are using, but it’s possible that they do not raise an error when something goes wrong, but just show a dialog or something. If that is the case, it will not be possible to catch an error, because there is no error.

Paul

You could also use it2be’s data plugin. That takes care of all kinds of errors when reading excel files :wink: