Skip to main content
==============
better_exchook
==============

A nicer drop-in-replacement for Python ``sys.excepthook``.
It will add some useful information for each frame,
like printing the relevant variables (relevant = referenced in the code line).
Also see `Python source and comments <https://github.com/albertz/py_better_exchook/blob/master/better_exchook.py>`_ for further details.

You can just copy over the file ``better_exchook.py`` to your project.
Or alternatively, it is also available `on PyPI <https://pypi.python.org/pypi/better_exchook`_
and can be installed via:

.. code::

pip install better_exchook

Python example code:

.. code:: python

try:
x = {1:2, "a":"b"}
def f():
y = "foo"
x, 42, sys.stdin.__class__, sys.exc_info, y, z
f()
except Exception:
better_exchook(*sys.exc_info())

Output:

.. code::

EXCEPTION
Traceback (most recent call last):
File "better_exchook.py", line 478, in <module>
line: f()
locals:
f = <local> <function f at 0x107f1de60>
File "better_exchook.py", line 477, in f
line: x, 42, sys.stdin.__class__, sys.exc_info, y, z
locals:
x = <global> {'a': 'b', 1: 2}
sys = <global> <module 'sys' (built-in)>
sys.stdin = <global> <open file '<stdin>', mode 'r' at 0x107d9f0c0>
sys.stdin.__class__ = <global> <type 'file'>
sys.exc_info = <global> <built-in function exc_info>
y = <local> 'foo'
z = <not found>
NameError: global name 'z' is not defined

Python example code:

.. code:: python

try:
f = lambda x: None
f(x, y)
except Exception:
better_exchook(*sys.exc_info())

Output:

.. code::

EXCEPTION
Traceback (most recent call last):
File "better_exchook.py", line 484, in <module>
line: f(x, y)
locals:
f = <local> <function <lambda> at 0x107f1df50>
x = <local> {'a': 'b', 1: 2}
y = <not found>
NameError: name 'y' is not defined

Python example code:

.. code:: python

try:
(lambda x: None)(__name__,
42) # multiline
except Exception:
better_exchook(*sys.exc_info())

Output:

.. code::

EXCEPTION
Traceback (most recent call last):
File "better_exchook.py", line 490, in <module>
line: (lambda x: None)(__name__,
42) # multiline
locals:
x = <local> {'a': 'b', 1: 2}
__name__ = <local> '__main__', len = 8
TypeError: <lambda>() takes exactly 1 argument (2 given)

Python example code:

.. code:: python

# use this to overwrite the global exception handler
sys.excepthook = better_exchook
# and fail
finalfail(sys)

Output:

.. code::

EXCEPTION
Traceback (most recent call last):
File "better_exchook.py", line 497, in <module>
line: finalfail(sys)
locals:
finalfail = <not found>
sys = <local> <module 'sys' (built-in)>
NameError: name 'finalfail' is not defined


Similar projects:
- `<https://github.com/patrys/great-justice>`_
- `Nose does something similar for assertion failures <http://nose.readthedocs.io/en/latest/plugins/failuredetail.html>`_.
- See `this <http://stackoverflow.com/questions/1308607/python-assert-improved-introspection-of-failure>`_ related StackOverflow question.


-- Albert Zeyer, <http://www.az2000.de>

Metadata

Release files for better-exchook 1.20160612.134916

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for better-exchook 1.20160612.134916
File Size Uploaded Provenance
better_exchook-1.20160612.134916.tar.gz 7.6 kB Without provenance Details

Release files / better_exchook-1.20160612.134916.tar.gz

Download URL better_exchook-1.20160612.134916.tar.gz
Size 7.6 kB
Tags Source
SHA-256 checksum
How to use checksums
120251674d19fd3f4fe1015d87e16e3cc8b067a95f6d22fb3d93d9ca3d54e3dd
BLAKE2b-256 checksum
How to use checksums
6f67ef03c9c7f2658a120a1137b85545ba8344f598d04df1d656a147540938eb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Security for better-exchook 1.20160612.134916

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

1.20160612.132345

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page