Python Forum

Full Version: Cancelling 'open directory' leading to crash
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi there,

So I'm pretty new to Python coding, I have old code here that isn't very robust when it comes to extreme user inputs. I'm trying to fix that.
The first button on my GUI loads in a file, and opens a directory to allow the user to select which file they want. When I click cancel or 'x' the directory, my program crashes.

I've had a search online and I'm not sure whether I'm not searching the right terminology, but I can't seem to find anything that fixes this. This should be fairly straightforward.
Could someone point me in the right direction?

I basically want a workaround that allows the program to take 'cancelling' or 'x'ing the directory as a reasonable input without crashing.

Thanks in advance.
Find the dialog in your code that opens the find-file window
and put try/ except / finally around it.
Then you will know the excact reason.
Probably if you put "pass" in the except part, it may pass, but you will not know why.

Paul