Handling a Python exception that occurs within an except clause

I believe what you’re seeing is the result of exception chaining, which is a change in Python 3.

From the Motivation section of the PEP:

During the handling of one exception (exception A), it is possible that another exception (exception B) may occur. In today’s Python (version 2.4), if this happens, exception B is propagated outward and exception A is lost. In order to debug the problem, it is useful to know about both exceptions. The __context__ attribute retains this information automatically.

The PEP then goes on to describe the new exception chaining (which is implemented in Py3k) in detail—it’s an interesting read. I learned something new today.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)