Package: jk_exceptionhelper
jk_exceptionhelperIntroductionThis 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:github.orgpypi.python.orgWhy 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 moduleImport this modulePlease include this module into your application using the following code:importjk_exceptionhelperAnalyse the exeptionExample:try:a=0b=5/aexceptExceptionasex:ee=jk_exceptionhelper.analyseException(ex)Noweecontains an instance ofExceptionObject.ExceptionObjectcontains all relevant information from the exception for your convenience to work with. (For details about theExceptionObjectAPI see below.)Output the exception dataExample:try:a=0b=5/aexceptExceptionasex:jk_exceptionhelper.analyseException(ex).dump()This will print all data collected to STDOUT. Example:ZeroDivisionError
: exceptionTextHR:
:	division by zero
: stackTrace:
:	(<stdin>:3, '')
\-API: FunctionsFunctionanalyseException()ExceptionObject analyseException()This function should be called at the first statement within anexceptblock. It returns an object of typeExceptionObjectcontaining all relevant information from the exception for your convenience to work with.API: ClassesClass 'ExceptionObject'FieldsTypeNameRequired?DescriptionclassexceptionClassoptionalThe original exception class. This instance will only be present ifanalyseException()was called within anexceptblock.strexceptionClassNamerequiredThe class name of the exception.strexceptionTextHRoptionalA human readable text that was contained within the exception.StackTraceItem[]stackTraceoptionalThe stack trace. The last item of the list is the topmost stack element.ExceptionObjectnestedExceptionoptionalThe parent exception object if this exception has been caught in anexceptblock.Static MethodsStatic MethodStackTraceItem fromJSON(dict data)StackTraceItem fromJSON(dict data)Deserialize a data structure created bytoJSON().MethodsMethodvoid dump()void dump()Print the contents of the exception to STDOUT.Example:try:a=0b=5/aexcept: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()')Methoddict toJSON(bool bRecursive = True)dict toJSON(bool bRecursive = True)Serialize the exception object to JSON format.Arguments:bool bRecursive: IfTrue(which is the default) nested exceptions are serialized as well. IfFalsethese get skipped.Example:try:a=0b=5/aexcept:edata=analyseException().toJSON()Methoddict toJSON(bool bRecursive = True)dict toJSON_flat()Same astoJSON(False).Arguments:(none)Contact InformationThis 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:Jürgen Knauth:jknauth@uni-goettingen.de,pubsrc@binary-overflow.deLicenseThis software is provided under the following license:Apache Software License 2.0