1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Anuncie Aqui
    Anuncie aqui você Também: fdantas@4each.com.br

[Python] get exception instance in __exit__ call of context manager

Discussão em 'Python' iniciado por Stack, Setembro 13, 2024.

  1. Stack

    Stack Membro Participativo

    In my code I have a method for logging exceptions that expects as an argument the instance of the exception that was thrown (so it can use str(exception) and traceback.format_exc(exception)). Now I want to call this method from within the __exit__ call of a context manager, but here I only have the type and value of the exception as well as the traceback.
    My question is, is there some way to get the raw exception that was caught by the __exit__ call or at least create a new one that I can then pass to my logging method?

    Continue reading...

Compartilhe esta Página