def raise_another_exception(*args, **kwargs):
        """If expected exception occurs, raise a new one."""
        ### try executing the function with the received
        ### arguments and storing the output
        try:
            output = raiser_func(*args, **kwargs)

        ### if an exception marked to be reraise is raised,
        ### do so

        except exceptions_to_reraise as err:
            raise err

        ### if an exception marked as expected is raised,
        ### it is caught and the new message is defined
        ### and the new exception is raiser in its place

        except expected_exceptions as err:

            ### first of all define the new exception
            ### message to use when raising

            ## if a new message was given, use it
            if new_message:
                msg = new_message

            ## otherwise assemble a message from the
            ## message of the exception caught, whether
            ## preformated or not

            else:

                ## grab exception message

                raw_msg = (
                    ## preformat exception message
                    "{}: {}".format(err.__class__.__name__, str(err))
                    if include_exception_name
                    ## or use it as-is
                    else str(err)
                )

                ## then pass it through the custom
                ## formatter
                msg = message_formatter(raw_msg)

            ### define the class for the new exceptions

            exception_class = (
                ## if new exception wasn't provided (it is
                ## None), use the same class as the exception
                ## caught
                err.__class__
                if new_exception is None
                ## otherwise use the new exception provided
                else new_exception
            )

            ### then pass the message to the exception
            ### class defined and raise the exception
            ### from the one we caught
            raise exception_class(msg) from err

        ### otherwise we just return the output
        else:
            return output
If expected exception occurs, raise a new one.
nodezator/ourstdlibs/exceptionutils.py