Skip to main content

As the python exception API is quite a bit obscure this python module wraps around python exceptions to provide a clean interface for analysis and logging purposes.

Project description

jk_exceptionhelper

Introduction

This python module wraps around python exceptions. As the python exception API is quite a bit obscure this python module provides a clean API for analysis and logging purposes.

Information about this module can be found here:

Why this module?

As the python exception API is quite a bit obscure this python module tries to solve this problem. By focusing on this problem in an isolated way improvements can easily be made without breaking and adapting a variety of implementations.

How to use this module

Import this module

Please include this module into your application using the following code:

import jk_exceptionhelper

Analyse the exeption

Example:

try:
	a = 0
	b = 5 / a
except Exception as ex:
	ee = jk_exceptionhelper.analyseException(ex)

Now ee contains an instance of ExceptionObject. ExceptionObject contains all relevant information from the exception for your convenience to work with. (For details about the ExceptionObject API see below.)

Output the exception data

Example:

try:
	a = 0
	b = 5 / a
except Exception as ex:
	jk_exceptionhelper.analyseException(ex).dump()

This will print all data collected to STDOUT. Example:

ZeroDivisionError
: exceptionTextHR:
:	division by zero
: stackTrace:
:	(<stdin>:3, '')
\-

API: Functions

Function analyseException()

ExceptionObject analyseException()

This function should be called at the first statement within an except block. It returns an object of type ExceptionObject containing all relevant information from the exception for your convenience to work with.

API: Classes

Class 'ExceptionObject'

Fields

Type Name Required? Description
class exceptionClass optional The original exception class. This instance will only be present if analyseException() was called within an except block.
str exceptionClassName required The class name of the exception.
str exceptionTextHR optional A human readable text that was contained within the exception.
StackTraceItem[] stackTrace optional The stack trace. The last item of the list is the topmost stack element.
ExceptionObject nestedException optional The parent exception object if this exception has been caught in an except block.

Static Methods

Static Method StackTraceItem fromJSON(dict data)

StackTraceItem fromJSON(dict data)

Deserialize a data structure created by toJSON().

Methods

Method void dump()

void dump()

Print the contents of the exception to STDOUT.

Example:

try:
	a = 0
	b = 5 / a
except:
	analyseException().dump()

This will print something like this:

ZeroDivisionError
: exceptionTextHR:
:	division by zero
: stackTrace:
:	(./test2.py:55, 'b = 5 / a')
:	(./test2.py:59, 'main3()')
:	(./test2.py:63, 'main2()')
:	(./test2.py:67, 'main1()')

Method dict toJSON(bool bRecursive = True)

dict toJSON(bool bRecursive = True)

Serialize the exception object to JSON format.

Arguments:

  • bool bRecursive : If True (which is the default) nested exceptions are serialized as well. If False these get skipped.

Example:

try:
	a = 0
	b = 5 / a
except:
	edata = analyseException().toJSON()

Method dict toJSON(bool bRecursive = True)

dict toJSON_flat()

Same as toJSON(False).

Arguments:

  • (none)

Contact Information

This is Open Source code. That not only gives you the possibility of freely using this code it also allows you to contribute. Feel free to contact the author(s) of this software listed below, either for comments, collaboration requests, suggestions for improvement or reporting bugs:

License

This software is provided under the following license:

  • Apache Software License 2.0

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

jk_exceptionhelper-0.2025.5.17.tar.gz (5.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

jk_exceptionhelper-0.2025.5.17-py3-none-any.whl (7.1 kB view details)

Uploaded Python 3

File details

Details for the file jk_exceptionhelper-0.2025.5.17.tar.gz.

File metadata

File hashes

Hashes for jk_exceptionhelper-0.2025.5.17.tar.gz
Algorithm Hash digest
SHA256 62cba0a0ea453e5de540c82e94d551f6732978aa5a7b6d257b307b3b4d6487f5
MD5 8d2e07bfabf0455b5abd020361a93a9a
BLAKE2b-256 ead731832e01a117be5835c7bb446028f0e3534f06b02932e732ce4d05094cf2

See more details on using hashes here.

File details

Details for the file jk_exceptionhelper-0.2025.5.17-py3-none-any.whl.

File metadata

File hashes

Hashes for jk_exceptionhelper-0.2025.5.17-py3-none-any.whl
Algorithm Hash digest
SHA256 6f3c89fbce2e6feef8dd459b83a8867109754a648782c228f374b0f98e573aa3
MD5 92b32c60e9bfb15443b1ad40aefc0fdc
BLAKE2b-256 1268b726d9c8dc4c82610a6c24d3f2af8510e42de605d8653266705f89607af8

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page