Exceptions

Revit Python Wrapper Exceptions

Custom RPW exceptions

exception rpw.exceptions.RpwCoerceError(value, target_type)

Bases: rpw.exceptions.RpwException, exceptions.ValueError

Coerce Error

exception rpw.exceptions.RpwException

Bases: exceptions.Exception

Revit Python Wrapper Base Exception

exception rpw.exceptions.RpwParameterNotFound(element, param_name)

Bases: rpw.exceptions.RpwException, exceptions.KeyError

Revit Python Wrapper Parameter Error

exception rpw.exceptions.RpwTypeError(type_expected, type_received=None)

Bases: exceptions.TypeError

Revit Python Wrapper Base Exception

exception rpw.exceptions.RpwWrongStorageType(storage_type, value)

Bases: rpw.exceptions.RpwException, exceptions.TypeError

Wrong Storage Type


Implementation


from rpw.utils.logger import logger


class RpwException(Exception):
    """ Revit Python Wrapper Base Exception """


class RpwTypeError(TypeError):
    """ Revit Python Wrapper Base Exception """
    def __init__(self, type_expected, type_received=None):
        type_received = type_received or 'not reported'
        msg = 'expected [{}], got [{}]'.format(type_expected, type_received)
        super(RpwTypeError, self).__init__(msg)


class RpwParameterNotFound(RpwException, KeyError):
    """ Revit Python Wrapper Parameter Error """
    def __init__(self, element, param_name):
        msg = 'parameter not found [element:{}]:[param_name:{}]'.format(element.Id, param_name)
        super(RpwParameterNotFound, self).__init__(msg)


class RpwWrongStorageType(RpwException, TypeError):
    """ Wrong Storage Type """
    def __init__(self, storage_type, value):
        msg = 'Wrong Storage Type: [{}]:[{}:{}]'.format(storage_type,
                                                        type(value), value)
        super(RpwWrongStorageType, self).__init__(msg)


class RpwCoerceError(RpwException, ValueError):
    """ Coerce Error """
    def __init__(self, value, target_type):
        msg = 'Could not cast value:{} to target_type:{}'.format(value, target_type)
        super(RpwCoerceError, self).__init__(msg)