Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Python Cover all exceptions

  1. Sep 12, 2016 #1
    I feel a bit dirty asking this..
    But I've written a fairly large program that is going to be deployed in a few weeks. Its a headless server. I've done error checking throughout the code where Im aware of it, but I'm worried about the things I have missed.

    Is there a way in python I can get it to continue on all exceptions? Perhaps write out an error log as well?? I highly doubt there is but thought I'd check :)
  2. jcsd
  3. Sep 12, 2016 #2


    Staff: Mentor

    Can you predict which exceptions are likely to be thrown? If so, maybe something like this is feasible:
    Code (Python):

       <some code that might throw>
    except (RuntimeError, TypeError, NameError):
       <handle error>
       <clean up>
  4. Sep 13, 2016 #3


    User Avatar
    Science Advisor

    You could double down on that slightly dirty feeling and write a program with an infinite loop that launches your server, captures stderr and diverts it to a logfile. In other words, an automatic log-it-and-reboot.
  5. Sep 13, 2016 #4
    Haha that might actually not be a bad idea.
    This is the classic case of I want a few weeks to test, and I have a few days :P

    I'm going to add some GOTO's jsut to make my fall from grace complete.
    And who needs comments in the code??
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook

Have something to add?
Draft saved Draft deleted