コード例 #1
0
def raise_with_cause(exc_cls, message, *args, **kwargs):
    """Helper to raise + chain exceptions (when able) and associate a *cause*.

    NOTE(harlowja): Since in py3.x exceptions can be chained (due to
    :pep:`3134`) we should try to raise the desired exception with the given
    *cause* (or extract a *cause* from the current stack if able) so that the
    exception formats nicely in old and new versions of python. Since py2.x
    does **not** support exception chaining (or formatting) our root exception
    class has a :py:meth:`~taskflow.exceptions.TaskFlowException.pformat`
    method that can be used to get *similar* information instead (and this
    function makes sure to retain the *cause* in that case as well so
    that the :py:meth:`~taskflow.exceptions.TaskFlowException.pformat` method
    shows them).

    :param exc_cls: the :py:class:`~taskflow.exceptions.TaskFlowException`
                    class to raise.
    :param message: the text/str message that will be passed to
                    the exceptions constructor as its first positional
                    argument.
    :param args: any additional positional arguments to pass to the
                 exceptions constructor.
    :param kwargs: any additional keyword arguments to pass to the
                   exceptions constructor.
    """
    if not issubclass(exc_cls, TaskFlowException):
        raise ValueError("Subclass of taskflow exception is required")
    excutils.raise_with_cause(exc_cls, message, *args, **kwargs)
コード例 #2
0
def raise_with_cause(exc_cls, message, *args, **kwargs):
    """Helper to raise + chain exceptions (when able) and associate a *cause*.

    NOTE(harlowja): Since in py3.x exceptions can be chained (due to
    :pep:`3134`) we should try to raise the desired exception with the given
    *cause* (or extract a *cause* from the current stack if able) so that the
    exception formats nicely in old and new versions of python. Since py2.x
    does **not** support exception chaining (or formatting) our root exception
    class has a :py:meth:`~taskflow.exceptions.TaskFlowException.pformat`
    method that can be used to get *similar* information instead (and this
    function makes sure to retain the *cause* in that case as well so
    that the :py:meth:`~taskflow.exceptions.TaskFlowException.pformat` method
    shows them).

    :param exc_cls: the :py:class:`~taskflow.exceptions.TaskFlowException`
                    class to raise.
    :param message: the text/str message that will be passed to
                    the exceptions constructor as its first positional
                    argument.
    :param args: any additional positional arguments to pass to the
                 exceptions constructor.
    :param kwargs: any additional keyword arguments to pass to the
                   exceptions constructor.
    """
    if not issubclass(exc_cls, TaskFlowException):
        raise ValueError("Subclass of taskflow exception is required")
    excutils.raise_with_cause(exc_cls, message, *args, **kwargs)
コード例 #3
0
ファイル: utils.py プロジェクト: sahid/python-tooz
def raise_with_cause(exc_cls, message, *args, **kwargs):
    """Helper to raise + chain exceptions (when able) and associate a *cause*.

    **For internal usage only.**

    NOTE(harlowja): Since in py3.x exceptions can be chained (due to
    :pep:`3134`) we should try to raise the desired exception with the given
    *cause*.

    :param exc_cls: the :py:class:`~tooz.ToozError` class to raise.
    :param message: the text/str message that will be passed to
                    the exceptions constructor as its first positional
                    argument.
    :param args: any additional positional arguments to pass to the
                 exceptions constructor.
    :param kwargs: any additional keyword arguments to pass to the
                   exceptions constructor.
    """
    if not issubclass(exc_cls, tooz.ToozError):
        raise ValueError("Subclass of tooz error is required")
    excutils.raise_with_cause(exc_cls, message, *args, **kwargs)
コード例 #4
0
ファイル: test_excutils.py プロジェクト: 4383/oslo.utils
 def raises_chained():
     try:
         raise Fail2("I have been broken")
     except Fail2:
         excutils.raise_with_cause(Fail1, "I was broken")
コード例 #5
0
ファイル: messaging.py プロジェクト: mdsalman729/ceilometer
def raise_delivery_failure(exc):
    excutils.raise_with_cause(DeliveryFailure,
                              encodeutils.exception_to_unicode(exc),
                              cause=exc)
コード例 #6
0
def raise_delivery_failure(exc):
    excutils.raise_with_cause(DeliveryFailure,
                              encodeutils.exception_to_unicode(exc),
                              cause=exc)
コード例 #7
0
ファイル: test_excutils.py プロジェクト: bdrich/neutron-lbaas
 def raises_chained():
     try:
         raise Fail2("I have been broken")
     except Fail2:
         excutils.raise_with_cause(Fail1, "I was broken")