Is it possible to catch any error in Python? I don’t care what the specific exceptions will be, because all of them will have the same fallback.
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Using
exceptby itself will catch any exception short of a segfault.You might want to handle KeyboardInterrupt separately in case you need to use it to exit your script:
There’s a nice list of basic exceptions you can catch here. I also quite like the traceback module for retrieving a call stack from the exception. Try
traceback.format_exc()ortraceback.print_exc()in an exception handler.