Python exception in exception

exception, python

Solution

In general it is not good design to have a catch-all except block, as it can mask programming errors. IMHO this is why it looks a little awful.

If you really want to fail graciouslly no matter what, then yes, put a nested try inside the except clause - but log the full traceback, otherwise it can get really hard to debug.

Problem

How do you handle an exception thrown by an except clause in Python? ``` def safeLoopingCall(self, *args, **kwargs): try: self.loopingCall(*args, **kwargs) except: self.log.exception("exception in task") ``` If an exception happens in the logger, we're out. What are best practices to avoid that? Do you surround an except by another try-except block (sounds awful)? This function is supposed to never propagate any exception.

Original source