Handling FileNotFoundException

Hi, I am trying to use a try/except block. It looks like there was a thread on this awhile back, but the user wasn’t importing the java module. I just wanted to make sure I’m not missing anything.

Thanks,

import java

dataSet =  event.source.parent.getComponent('Table').data

try:
	filePath = system.dataset.exportExcel("totals.xls", 1, dataSet)

except java.io.FileNotFoundException, e:
	system.gui.errorBox('File is currently open.  Please close file and export again.')
	
if filePath is not None:
	system.net.openURL("file://"+filePath)

Change line 1 to

from java.io import FileNotFoundException

And the except line to

except FileNotFoundException,e:

Importing classes is slooooww. Only import what you need.

2 Likes

Thanks for the response. I added the changes to the code, however I am still not catching the error. I should have noted in my original post that exception is thrown if I have the file open, and I export the dataset a second time. I dug up the old thread from 2010, here is a link:

http://forum.inductiveautomation.com/t/excel-export-to-in-use-file-try-except-problem/2191