Skip to main content

Rise class for formatting thrown exception messages.

Project description

RaiseTool

The project contains small class for formatting thrown exception messages.

The message can be formatted with information about the class, method, and line number where the exception was thrown.

Public methods

Raise.message(message:str, class_name:Optional[str],currentframe:Optional[FrameType])-> str
Raise.attribute_error(message:str, class_name:Optional[str],currentframe:Optional[FrameType])-> AttributeError
Raise.connection_error(message:str, class_name:Optional[str],currentframe:Optional[FrameType])-> ConnectionError
Raise.key_error(message:str, class_name:Optional[str],currentframe:Optional[FrameType])-> KeyError
Raise.os_error(message:str, class_name:Optional[str],currentframe:Optional[FrameType])-> OSError
Raise.syntax_error(message:str, class_name:Optional[str],currentframe:Optional[FrameType])-> SyntaxError
Raise.type_error(message:str, class_name:Optional[str],currentframe:Optional[FrameType])-> TypeError
Raise.value_error(message:str, class_name:Optional[str],currentframe:Optional[FrameType])-> ValueError

Usage examples

import inspect
from raisetool.formatter import Raise


class Example:
    def __init__(self):
        print(f"1: {Raise.message('example message 1')}")
        print(
            f"2: {Raise.message('example message 2', self.__class__.__name__)}"
        )
        print(
            f"3: {Raise.message('example message 3', self.__class__.__name__, inspect.currentframe(), )}"
        )
        try:
            raise Raise.value_error(
                "example message 4",
                self.__class__.__name__,
                inspect.currentframe(),
            )
        except ValueError as ex:
            print(f"4: {ex.__class__.__name__}: {ex}")


if __name__ == "__main__":
    obj = Example()

Output:

1: example message 1
2: Example: example message 2
3: Example.__init__ [line:21]: example message 3
4: ValueError: Example.__init__ [line:24]: example message 4

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

raisetool-1.0.0.tar.gz (2.9 kB view hashes)

Uploaded Source

Built Distribution

raisetool-1.0.0-py3-none-any.whl (3.6 kB view hashes)

Uploaded Python 3

Supported by

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