'Is implicitly using null argument as a flag good code style

Which of below is a better coding style, and why? 1)

public string GetValue(string setting, string error)
{
    var val = GetSettingFromSomewhere(setting);
    if (val==null && string.IsNullOrEmpty(error)) throw Exception(error);
    return val;
}

Or 2)

public string GetValue(string setting, bool isRequired, string error)
{
    var val = GetSettingFromSomewhere(setting);
    if (val==null && isRequired) throw Exception(error);
    return val;
}


Solution 1:[1]

IsNullOrEmpty function is Light and it's returning a Boolean so I guess for this case in particular it doesn't really matter. What matters is what you think makes your function more readable to the people who might use the function

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Anthony N.