@@ -16,9 +16,8 @@ interpreter.
16
16
17
17
.. index :: object: traceback
18
18
19
- The module uses traceback objects --- this is the object type that is stored in
20
- the :data: `sys.last_traceback ` variable and returned as the third item from
21
- :func: `sys.exc_info `.
19
+ The module uses traceback objects --- these are objects of type :class: `types.TracebackType `,
20
+ which are assigned to the ``__traceback__ `` field of :class: `BaseException ` instances.
22
21
23
22
.. seealso ::
24
23
@@ -81,7 +80,7 @@ The module defines the following functions:
81
80
82
81
.. function :: print_exc(limit=None, file=None, chain=True)
83
82
84
- This is a shorthand for ``print_exception(* sys.exc_info (), limit, file,
83
+ This is a shorthand for ``print_exception(sys.exception (), limit, file,
85
84
chain) ``.
86
85
87
86
@@ -444,24 +443,24 @@ exception and traceback:
444
443
try:
445
444
lumberjack()
446
445
except IndexError:
447
- exc_type, exc_value, exc_traceback = sys.exc_info ()
446
+ exc = sys.exception ()
448
447
print("*** print_tb:")
449
- traceback.print_tb(exc_traceback , limit=1, file=sys.stdout)
448
+ traceback.print_tb(exc.__traceback__ , limit=1, file=sys.stdout)
450
449
print("* ** print_exception:")
451
- traceback.print_exception(exc_value , limit=2, file=sys.stdout)
450
+ traceback.print_exception(exc , limit=2, file=sys.stdout)
452
451
print("*** print_exc:")
453
452
traceback.print_exc(limit=2, file=sys.stdout)
454
453
print("* ** format_exc, first and last line:")
455
454
formatted_lines = traceback.format_exc().splitlines()
456
455
print(formatted_lines[0])
457
456
print(formatted_lines[-1])
458
457
print("*** format_exception:")
459
- print(repr(traceback.format_exception(exc_value )))
458
+ print(repr(traceback.format_exception(exc )))
460
459
print("* ** extract_tb:")
461
- print(repr(traceback.extract_tb(exc_traceback )))
460
+ print(repr(traceback.extract_tb(exc.__traceback__ )))
462
461
print("*** format_tb:")
463
- print(repr(traceback.format_tb(exc_traceback )))
464
- print("* ** tb_lineno:", exc_traceback .tb_lineno)
462
+ print(repr(traceback.format_tb(exc.__traceback__ )))
463
+ print("* ** tb_lineno:", exc.__traceback__ .tb_lineno)
465
464
466
465
The output for the example would look similar to this:
467
466
0 commit comments