Exceptions¶
Handling and displaying exceptions with ictr.
Automatic Capture¶
Use the errorx (or alias ex) flavor to automatically capture and display
active exceptions.
>>> try:
... 1 / 0
... except ZeroDivisionError:
... ictr( 'errorx', address = 'doctest' )( 'Calculation failed.' )
>>> # Verify output contains exception info
>>> output = capture.getvalue( )
>>> '[ZeroDivisionError] division by zero' in output
True
>>> 'Calculation failed.' in output
True
Tracebacks¶
You can enable stack traces for any flavor via configuration, but errorx and
abortx have them enabled by default.
>>> def faulty_function( ):
... raise ValueError( 'Invalid value' )
>>> try:
... faulty_function( )
... except ValueError:
... ictr( 'errorx', address = 'doctest' )( 'Operation failed.' )
>>> output = capture.getvalue( )
>>> '[ValueError] Invalid value' in output
True
>>> 'faulty_function( )' in output
True