Skip to main content

Convenience facilities for managing exceptions.

Function logexc(func)

Decorator to log exceptions and reraise.

Function logexc_gen(genfunc)

Decorator to log exceptions and reraise for generators.

Function LogExceptions(conceal=False)

Wrapper of NoExceptions which reports exceptions and optionally suppresses them.

Function noexc(func)

Decorator to wrap a function which should never raise an exception. Instead, any raised exception is attempted to be logged.

A significant side effect is of course that if the function raises an exception it now returns None. My primary use case is actually to wrap logging functions, which I have had abort otherwise sensible code.

Function noexc_gen(func)

Decorator to wrap a generator which should never raise an exception. Instead, any raised exception is attempted to be logged and iteration ends.

My primary use case is wrapping generators chained in a pipeline, as in cs.later.Later.pipeline.

Class NoExceptions

A context manager to catch all exceptions and log them. Arguably this should be a bare try...except but that's syntacticly noisy and separates the catch from the top. For simple function calls return_exc_info() is probably better.

Function return_exc_info(func, *args, **kwargs)

Run the supplied function and arguments. Return (func_return, None) in the case of successful operation and (None, exc_info) in the case of an exception.

exc_info is a 3-tuple of (exc_type, exc_value, exc_traceback) as returned by sys.exc_info(). If you need to protect a whole suite and would rather not move it into its own function, consider the NoExceptions context manager.

Function returns_exc_info(func)

Decorator function to wrap functions whose exceptions should be caught, such as inside event loops or worker threads.

It causes a function to return (func_return, None) in the case of successful operation and (None, exc_info) in the case of an exception.

exc_info is a 3-tuple of (exc_type, exc_value, exc_traceback) as returned by sys.exc_info().

Function safe_property(func)

Substitute for @property which lets AttributeErrors escape as RuntimeErrors.

Function transmute(exc_from, exc_to=None)

Decorator to transmute an inner exception to another exception type.

The motivating use case is properties in a class with a getattr method; if some inner operation of the property function raises AttributeError then the property is bypassed in favour of getattr. Confusion ensues.

In principle this can be an issue with any exception raised from "deeper" in the call chain, which can be mistaken for a "shallow" exception raise by the function itself.

Function unattributable(func)

Decorator to transmute AttributeError into a RuntimeError.

Function unimplemented(func)

Decorator for stub methods that must be implemented by a stub class.

Release files for cs-excutils 20190220

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

Source distribution (sdist)

Source distribution for cs-excutils 20190220
File Size Uploaded
cs.excutils-20190220.tar.gz 4.4 kB Details

Release files / cs.excutils-20190220.tar.gz

Download URL cs.excutils-20190220.tar.gz
Size 4.4 kB
Tags Source
SHA-256 checksum
How to use checksums
4fd5bf42818abeb2a02d9d12b4f89be83fce70da32cc0cfe57f32e944d239e58
BLAKE2b-256 checksum
How to use checksums
ab0772467faff91de73c76f5d820b7e520bbd60a87d1e0f92a23d263e03cbc37
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.11.0 pkginfo/1.4.2 requests/2.18.4 setuptools/40.0.0 requests-toolbelt/0.8.0 tqdm/4.23.0 CPython/3.6.8

Release history Release notifications | RSS feed

This release

20190220 This release

1 release file

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