# Trap the error popup

**URL:** <https://forum.inductiveautomation.com/t/trap-the-error-popup/51610>\
**Category:** Ignition\
**Tags:** vision\
**Created:** [October 5, 2021, 10:31am UTC](https://forum.inductiveautomation.com/t/trap-the-error-popup/51610 "2021-10-05T10:31:37Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![mukul](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/mukul/32/26858_2.png) [@mukul](https://forum.inductiveautomation.com/u/mukul)\
**Post date:** [October 5, 2021, 10:31am UTC](https://forum.inductiveautomation.com/t/trap-the-error-popup/51610/1 "2021-10-05T10:31:37Z")

</div>

Hi  
How can I trap this error which shows up when I close the save file window without saving file  
I am using a button to generate a csv file - when i save the file there is no popup but if i cancel the file saving it gives me this popup

 ![Screenshot_3](https://us1.discourse-cdn.com/inductiveautomation/original/3X/3/7/37d436a33243013a204bde9d4ccddc8d8401670d.png)

 ![Screenshot_1](https://us1.discourse-cdn.com/inductiveautomation/original/3X/c/b/cb10329f0be345f983348dc1eb0f06672fa0ddab.png)  
 ![Screenshot_2](https://us1.discourse-cdn.com/inductiveautomation/original/3X/1/3/139c24fa0933827b9b9f609e8c967245e73ae33d.png)

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [October 5, 2021, 10:35am UTC](https://forum.inductiveautomation.com/t/trap-the-error-popup/51610/2 "2021-10-05T10:35:24Z")

</div>

Troubleshooting scripts is difficult if you don’t share the script. 😉

---

<div class="post-metadata">

**Author:** ![mukul](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/mukul/32/26858_2.png) [@mukul](https://forum.inductiveautomation.com/u/mukul)\
**Post date:** [October 5, 2021, 10:36am UTC](https://forum.inductiveautomation.com/t/trap-the-error-popup/51610/3 "2021-10-05T10:36:31Z")

</div>

```auto
import csv
import datetime
# Obtain the java init date from the Input on the screen 
datastart = event.source.parent.getComponent('Start Date').date
dataend =event.source.parent.getComponent('Start Date 1').date
#Calculate the number of hours in between the two dates 
 
 
 
#Return size is the data points to be collected from starttime to endtime
Return_size=system.date.secondsBetween(datastart, dataend)/event.source.parent.getComponent('Dropdown_Datapoints').selectedValue
print(Return_size)
data = system.tag.queryTagHistory(paths = ["[edge]Engine1_rpm.value","[edge]Pump1_RPM.value","[edge]Pump1_strokes.value","[edge]Pressure_sensor_pump1.value","","[edge]FlowRatePump1.value","[edge]Pump1_flow_Total.value"],startDate=datastart, endDate=dataend, returnSize=Return_size, aggregationMode="Average", returnFormat='Wide')
 
csv = system.dataset.toCSV(data)
  
CustomerName = event.source.parent.getComponent('cstnm').text
JobNumber = event.source.parent.getComponent('Jobnumber').text
From=system.date.format(datastart, "yyyy-MM-dd-HH-mm-ss")
To=system.date.format(dataend, "yyyy-MM-dd-HH-mm-ss")
  
 
fnm = "PUMP1_DATA_"+From+"_to_"+To+".csv"
filename = system.file.saveFile(fnm)
 
system.file.writeFile(filename,csv)

```

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [October 5, 2021, 10:40am UTC](https://forum.inductiveautomation.com/t/trap-the-error-popup/51610/4 "2021-10-05T10:40:08Z")

</div>

Using the [example in the manual](https://docs.inductiveautomation.com/display/DOC81/system.file.saveFile), try this:

```python
filename = system.file.saveFile(fnm)
if fileName is not None:
    system.file.writeFile(filename,csv)

```

---

<div class="post-metadata">

**Author:** ![mukul](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/mukul/32/26858_2.png) [@mukul](https://forum.inductiveautomation.com/u/mukul)\
**Post date:** [October 5, 2021, 10:44am UTC](https://forum.inductiveautomation.com/t/trap-the-error-popup/51610/5 "2021-10-05T10:44:53Z")

</div>

> [@JordanCClark](#):
>
> ```python
> if fileName is not None:
> system.file.writeFile(filename,csv)
> 
> ```

Working - just had to change the fileName to filename as fileName does not exist 🙂

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [October 5, 2021, 10:45am UTC](https://forum.inductiveautomation.com/t/trap-the-error-popup/51610/6 "2021-10-05T10:45:47Z")

</div>

Sorry about that. I tend to use camel case in my code. 🙂

---

<div class="post-metadata">

**Author:** ![bkarabinchak.psi](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bkarabinchak.psi/32/83567_2.png) [@bkarabinchak.psi](https://forum.inductiveautomation.com/u/bkarabinchak.psi)\
**Post date:** [October 5, 2021, 12:17pm UTC](https://forum.inductiveautomation.com/t/trap-the-error-popup/51610/7 "2021-10-05T12:17:07Z")

</div>

It looks like @JordanCClark already solved your problem, but generally speaking if you want to catch an error you use a `try\except` clause. In your case, you’d have to do

```auto
import java.lang.NullPointerExecption

try:
    # Your function call here
except NullPointerException, e:
    # Log the error and handle gracefully to the user here

```
