Say, I have a big application in python running on a server a few times per day and sometimes it crashes. I want, when it crashes, it at least to release all the resources such as db connection, file handlers, etc.
I've got some "try ... except" blocks in it, but who knows where it's going to crash next? It's possible it'll crash somewhere where the code isn't wrapped into "try ... except".
What's a recommended way to improve it? Should I wrap the whole script body into "try ... except" as the last resort? Or what?
Wrap the whole code with a try-catch is the most simple way but it doesn't fix the problem.
I think the best way is to find out the root cause of crash and take care of it even just print an error message and exit.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With