import typing


def convert_value(dtype: typing.Any, value: typing.Any, default: typing.Any = None) -> typing.Union[typing.Any, None]:
    """
    Return the passed value in the specified value if it is not None and does not raise an Exception
    while converting. Returns the passed default if the conversion failed

    :param dtype: The datatype the value should be returned
    :param value: The value that should be converted
    :param default: The default Value that should be returned if the conversion failed
    :return: The converted value or the default passed value
    """
    try:
        if value is None:
            return default
        return dtype(value)

    except Exception:
        return default