Mars Lee Mars Lee - 2 years ago 78
Python Question

How to make Python executable pause when it raises an error?

So I know I can make Python executable using


However, every time it raises an error, it will instantly end the program, so I can't find what is the error.

I know I probably can use
to stop it.

But if the code raises error before it meets
, it will just shut down.

To sum up, how to make it keep not shutting down, so I can see where is the mistake?

Answer Source

If you are running the executable just by double clicking, try running it from console. For e.g. in Windows:

In cmd, run

cd executable_path myexecutable.exe

A better way would be to introduce logger so that other modules with logging implemented can write to files.

Also, you can put the code in try-except block:

    print('Here is where the exception is')
except Exception as e:
    print('Unexpected error:' + str(e))
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download