Trap the error popup

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

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

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, dataend)/event.source.parent.getComponent('Dropdown_Datapoints').selectedValue
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, "yyyy-MM-dd-HH-mm-ss"), "yyyy-MM-dd-HH-mm-ss")
fnm = "PUMP1_DATA_"+From+"_to_"+To+".csv"
filename = system.file.saveFile(fnm)

Using the example in the manual, try this:

filename = system.file.saveFile(fnm)
if fileName is not None:

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

1 Like

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


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

import java.lang.NullPointerExecption

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