# Excel Export to in-use file try...except problem

**URL:** <https://forum.inductiveautomation.com/t/excel-export-to-in-use-file-try-except-problem/2191>\
**Category:** Archived Topics\
**Created:** [September 14, 2010, 12:21am UTC](https://forum.inductiveautomation.com/t/excel-export-to-in-use-file-try-except-problem/2191 "2010-09-14T00:21:12Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![chache](https://avatars.discourse-cdn.com/v4/letter/c/90db22/32.png) [@chache](https://forum.inductiveautomation.com/u/chache)\
**Post date:** [September 14, 2010, 12:21am UTC](https://forum.inductiveautomation.com/t/excel-export-to-in-use-file-try-except-problem/2191/1 "2010-09-14T00:21:12Z")

</div>

Hi all,

When I try to export to a file that is in use, it fails (as it should) with a java.io.fileNotFoundException. What I’d like to do is catch the error and print my own message, but the error doesn’t seem to be getting caught.

Basically:

`
try:
  #x=5/0
  fpmi.db.exportExcel("mydata.xls", 1, fpmi.db.toDataSet(ExportData))
except:
  fpmi.gui.messageBox("The file couldn't be overwritten because it is in use.")`

With this code the java exception appears anyways. If I intentionally cause an exception in the try (by dividing by 0 for example), then I get the message I expect, however the java file exception never gets caught. Any ideas?

---

<div class="post-metadata">

**Author:** ![Travis.Cox](https://avatars.discourse-cdn.com/v4/letter/t/b9bd4f/32.png) [@Travis.Cox](https://forum.inductiveautomation.com/u/Travis.Cox)\
**Post date:** [September 14, 2010, 3:12pm UTC](https://forum.inductiveautomation.com/t/excel-export-to-in-use-file-try-except-problem/2191/2 "2010-09-14T15:12:45Z")

</div>

Unfortunately in FactoryPMI you cannot catch some of our errors, the error box will popup.

---

<div class="post-metadata">

**Author:** ![chache](https://avatars.discourse-cdn.com/v4/letter/c/90db22/32.png) [@chache](https://forum.inductiveautomation.com/u/chache)\
**Post date:** [September 14, 2010, 4:42pm UTC](https://forum.inductiveautomation.com/t/excel-export-to-in-use-file-try-except-problem/2191/3 "2010-09-14T16:42:08Z")

</div>

Alrighty, Thanks!
