I’m trying to export a file using the option exportExcel and it works well most of the times but there are 2 scenarios where is throwing an error

If the file is open or if the user doesnt enter the file extension(xls)
I’m using a try catch but for an unknown reason is not catching the error
Could you let me know what I’m doing wrong?
try:
filePath = system.dataset.exportExcel(fileName, 1, NewDataSetY)
if filePath != None:
filePath = filePath.replace(' ', '%20')
filePath = filePath.replace('\\', '/')
system.net.openURL("file:" + filePath)
except Exception:
'error'
Thank you
Can you copy the full details of the error message? It’s probably calling out to open the file along a different code path; there may or may not be a way to work around the issue.
Consider using two except blocks, as jython's standard Exception
won't catch pure java exceptions. Like so:
import java.lang.Exception
try:
# something something something
except Exception, e:
# jython exception
except java.lang.Exception, e:
# java exception
Update:
For better coverage and less chance of name conflict, I've been recommending this construct lately:
from java.lang import Throwable
try:
# something something something
except Throwable, t:
# Java exception handling
except Exception, e:
# Jython exception handling
7 Likes
Doesn’t work for the FileNotFoundException thrown here when the file is open.