# Catch IOException?

**URL:** <https://forum.inductiveautomation.com/t/catch-ioexception/18612>\
**Category:** Ignition\
**Created:** [June 25, 2018, 4:48pm UTC](https://forum.inductiveautomation.com/t/catch-ioexception/18612 "2018-06-25T16:48:35Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![emanuel\_serrano](https://avatars.discourse-cdn.com/v4/letter/e/22d042/32.png) [@emanuel\_serrano](https://forum.inductiveautomation.com/u/emanuel_serrano)\
**Post date:** [June 25, 2018, 4:48pm UTC](https://forum.inductiveautomation.com/t/catch-ioexception/18612/1 "2018-06-25T16:48:35Z")

</div>

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

![](https://us1.discourse-cdn.com/inductiveautomation/original/2X/1/18a780f4f686dfd5bd8202bf4632d412decc7a6f.png)

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?

```auto
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

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [June 28, 2018, 5:21pm UTC](https://forum.inductiveautomation.com/t/catch-ioexception/18612/2 "2018-06-28T17:21:43Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [June 28, 2018, 5:55pm UTC](https://forum.inductiveautomation.com/t/catch-ioexception/18612/3 "2018-06-28T17:55:35Z")

</div>

Consider using two except blocks, as jython's standard `Exception` won't catch pure java exceptions. Like so:

```python
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:

```python
from java.lang import Throwable

try:
    # something something something
except Throwable, t:
    # Java exception handling
except Exception, e:
    # Jython exception handling

```

---

<div class="post-metadata">

**Author:** ![ethomason](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/ethomason/32/43338_2.png) [@ethomason](https://forum.inductiveautomation.com/u/ethomason)\
**Post date:** [June 28, 2018, 6:09pm UTC](https://forum.inductiveautomation.com/t/catch-ioexception/18612/4 "2018-06-28T18:09:45Z")

</div>

Doesn’t work for the FileNotFoundException thrown here when the file is open.
