Skip to main content

Raise exceptions with a function instead of a statement.

Provides a minimal and portable interface for raising exceptions with all the advantages of functions over syntax.

Versioning

This library’s version numbers follow the SemVer 2.0.0 specification.

Installation

pip install raise

Usage

Import raise_:

from raise_ import raise_

Raise an exception:

raise_(Exception('foo'))

Raise an exception with a traceback:

raise_(Exception('foo'), traceback)

Raise in a lambda:

lambda x: x if x > 0 else raise_(ValueError('x is too small!'))

And of course because raise_ is a function, you can combine it with functools.partial and other functional programming libraries and techniques for many more uses.

Surprises

raise_ clears __traceback__ if you don’t pass in a traceback, same as if you passed in None. If you want the Python 3 behavior of reusing the __traceback__, you should explicitly pass it in:

raise_(exception, exception.__traceback__)

Or, if you want to gracefully degrade on Python implementations which do not have __traceback__ on their exceptions:

raise_(exception, getattr(exception, '__traceback__', None))

Portability

Portable to all releases of both Python 3 and Python 2.

(The oldest tested is 2.5, but it will likely work on all Python 2 versions and probably on even earlier versions.)

For implementations of Python that do not support raising with a custom traceback, a “no traceback” variant is included in the source that can be installed manually.

Release files for raise 1.1.9

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

Source distribution (sdist)

Source distribution for raise 1.1.9
File Size Uploaded
raise-1.1.9.tar.gz 3.7 kB Details

Built distributions (wheels)

Table of built distributions (wheels) for raise 1.1.9
File Interpreter ABI Platform
raise-1.1.9-py3-none-any.whl Python 3 none any Details
raise-1.1.9-py2-none-any.whl Python 2 none any Details

Total release size: 9.9 kB

Release files / raise-1.1.9.tar.gz

Download URL raise-1.1.9.tar.gz
Size 3.7 kB
Tags Source
SHA-256 checksum
How to use checksums
ac3628721cd6e98e927c3baa238f346e3fb9ed4db47cd5c70a52532b97c8ce97
BLAKE2b-256 checksum
How to use checksums
6940557c5ecca5a1866b5c463029dc3cb7dfda64cc0862506b25c783b776e9a4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.9.2

Release files / raise-1.1.9-py3-none-any.whl

Download URL raise-1.1.9-py3-none-any.whl
Size 3.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
7d390174139551dee55e790541dacf11879d07e79d063e457c12f5b6bb55ab59
BLAKE2b-256 checksum
How to use checksums
18729e235410aef14a393733257f0130f05f355d51d257d708ef8de499fe1d68
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.9.2

Release files / raise-1.1.9-py2-none-any.whl

Download URL raise-1.1.9-py2-none-any.whl
Size 3.0 kB
Tags Python 2
SHA-256 checksum
How to use checksums
b6d06d757fac7b73b2a6becefb7ce31a8e154d040ca183b5701a31b2a02ab4d1
BLAKE2b-256 checksum
How to use checksums
f05783e89800245600cd448c3f06d6e9c6cdf9e9dad0d23221534d3d20241219
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.9.2

Release history Release notifications | RSS feed

This release

1.1.9 This release

3 release files

1.1.8

3 release files

1.1.7

3 release files

1.1.6

3 release files

1.1.5

3 release files

1.1.4

3 release files

1.1.3

3 release files

1.1.2

3 release files

1.1.1

2 release files

1.1.0

2 release files

1.0.1

2 release files

1.0.0

2 release files

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