title: How to detect if an exception has been raised from a try block in python?
body: <p>For example:</p>
  
  <pre><code>class ExceptionMeta(type):
    def __call__(cls, *args, **kwargs):
      if exception_raised_from_try_block:
         do_something
      else:
         do_something_else
  
  class TimeOutError(metaclass = ExceptionMeta):
    pass
  
  try:
    raise TimeOutError
  except Exception as e:
    pass
  </code></pre>
  
  <p>The actual problem is that I have a code block in which I am having a TimeOut error in the try - except block. Every time a TimeOut error is raised, I catch it in try - except block and issue retry for 5 times. This TimeOut error has an object which will collect the error traces in case the exception is raised so as to provide more context while debugging the issue. But every time the exception is raised in the try block, the call goes to call function and it ends up collecting the traces for that error which I dont want as I am just retrying again in the except block</p>
  
  <p>Is there any way in python using inspection or some other module which can tell me that exception was raised from a try block?</p>