Skip to content

handle invalid arguments#143

Open
egandunning wants to merge 1 commit intoJefferson-Henrique:masterfrom
egandunning:exporter-error-handling
Open

handle invalid arguments#143
egandunning wants to merge 1 commit intoJefferson-Henrique:masterfrom
egandunning:exporter-error-handling

Conversation

@egandunning
Copy link

Running Exporter.py with invalid arguments resulted in the following error message:

$ python Exporter.py --whoops
Traceback (most recent call last):
File "Exporter.py", line 79, in <module>
main(sys.argv[1:])
File "Exporter.py", line 75, in main
outputFile.close()
UnboundLocalError: local variable 'outputFile' referenced before assignment

I moved all file io into a with block, and removed the finally block. This way, if getopt() throws an exception, the program won't call close() on an uninitialized variable.

Running the same command now gives the following output:

$ python Exporter.py --whoops
Arguments parser error, try -h

option --whoops not recognized

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant