Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I don't think you can do this in Python 2.x, but something similar to this functionality is part of Python 3. From <a href="http://www.python.org/dev/peps/pep-3134/" rel="noreferrer">PEP 3134</a>:</p> <blockquote> <p>In today's Python implementation, exceptions are composed of three parts: the type, the value, and the traceback. The 'sys' module, exposes the current exception in three parallel variables, exc_type, exc_value, and exc_traceback, the sys.exc_info() function returns a tuple of these three parts, and the 'raise' statement has a three-argument form accepting these three parts. Manipulating exceptions often requires passing these three things in parallel, which can be tedious and error-prone. Additionally, the 'except' statement can only provide access to the value, not the traceback. Adding the '<strong>traceback</strong>' attribute to exception values makes all the exception information accessible from a single place.</p> </blockquote> <p>Comparison to C#:</p> <blockquote> <p>Exceptions in C# contain a read-only 'InnerException' property that may point to another exception. Its documentation [10] says that "When an exception X is thrown as a direct result of a previous exception Y, the InnerException property of X should contain a reference to Y." This property is not set by the VM automatically; rather, all exception constructors take an optional 'innerException' argument to set it explicitly. The '<strong>cause</strong>' attribute fulfills the same purpose as InnerException, but this PEP proposes a new form of 'raise' rather than extending the constructors of all exceptions. C# also provides a GetBaseException method that jumps directly to the end of the InnerException chain; this PEP proposes no analog.</p> </blockquote> <p>Note also that Java, Ruby and Perl 5 don't support this type of thing either. Quoting again:</p> <blockquote> <p>As for other languages, Java and Ruby both discard the original exception when another exception occurs in a 'catch'/'rescue' or 'finally'/'ensure' clause. Perl 5 lacks built-in structured exception handling. For Perl 6, RFC number 88 [9] proposes an exception mechanism that implicitly retains chained exceptions in an array named @@.</p> </blockquote>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload