raisetool

Author: Jacek Kotlarski –<szumak@virthost.pl> Created: 08.05.2023

Purpose: This module provides the Raise class, a utility for creating and formatting standardized exception messages. It helps in generating rich, informative error messages that include details like the class name, method name, and line number where the error occurred, facilitating easier debugging.

class jsktoolbox.raisetool.Raise[source]

Bases: NoDynamicAttributes

A utility class for formatting and creating exception objects.

This class contains only static methods and is not meant to be instantiated. It serves as a centralized tool for generating consistent and descriptive error messages and exception instances throughout a project.

classmethod message(message, class_name='', currentframe=None)[source]

Format a message string with contextual information.

This method constructs a detailed message string by prepending the class name, method name, and line number.

### Arguments: * message: str - The core message to be formatted. * class_name: str - The name of the class from which the call is made. Defaults to “”. * currentframe: Optional[FrameType] - A frame object from inspect.currentframe().

### Returns: str - A formatted message string with contextual details.

Parameters:
  • message (str)

  • class_name (str)

  • currentframe (FrameType | None)

Return type:

str

classmethod error(message, exception=<class 'Exception'>, class_name='', currentframe=None)[source]

Create an exception instance with a formatted message.

This is the primary factory method for creating standardized exceptions. It validates the exception type and formats the message.

### Arguments: * message: str - The core error message. * exception: type[Exception] - The exception class to be instantiated. Defaults to Exception. * class_name: str - The name of the class where the error occurred. Defaults to “”. * currentframe: Optional[FrameType] - A frame object from inspect.currentframe().

### Returns: Exception - An instance of the specified exception class.

### Raises: * TypeError: If the exception argument is not a class that inherits from Exception.

Parameters:
Return type:

Exception

__setattr__(name, value)

Prevent dynamic attribute assignment on instances.

### Raises: * AttributeError: Attribute not previously declared.

Parameters:
Return type:

None