https://github.com/jlumbroso/templated-exceptions
Python package to help create verbose exceptions with message instantiated from templates. 🐞 💬 💡
https://github.com/jlumbroso/templated-exceptions
Last synced: 7 months ago
JSON representation
Python package to help create verbose exceptions with message instantiated from templates. 🐞 💬 💡
- Host: GitHub
- URL: https://github.com/jlumbroso/templated-exceptions
- Owner: jlumbroso
- License: lgpl-3.0
- Created: 2020-12-30T04:48:12.000Z (almost 5 years ago)
- Default Branch: main
- Last Pushed: 2021-01-14T04:58:09.000Z (almost 5 years ago)
- Last Synced: 2025-01-29T22:33:15.429Z (9 months ago)
- Language: Python
- Homepage:
- Size: 59.6 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Templated Exceptions
## Example
A templated exception is an exception class which, instead of taking a static
message when initialized/raised (as typical Python exception classes are used),
is defined with a template and provided only template variables when raised.For instance, in this example, we define an `ExampleRuntimeException` to report
on errors related to the command-line parameters provided to a program:```python
import templated_exceptionsclass ExampleRuntimeException(templated_exceptions.TemplatedException, RuntimeError):
TEMPLATE = "Program unexpectedly failed with input args: {args}."raise ExampleRuntimeException(args=["myprogram", "-e", "--badflag"])
```will produce the following exception stack trace:
```
Traceback (most recent call last):
File "", line 1, in
ExampleRuntimeException: Program unexpectedly failed with input args: ['myprogram', '-e', '--badflag'].
```