using System; namespace Avalonia.Data { /// /// An exception returned through signaling that a /// requested binding expression could not be evaluated because of an error in one of /// the links of the binding chain. /// public class BindingChainException : Exception { private readonly string _message; /// /// Initializes a new instance of the class. /// public BindingChainException() { _message = "Binding error"; } /// /// Initializes a new instance of the class. /// /// The error message. public BindingChainException(string message) { _message = message; } /// /// Initializes a new instance of the class. /// /// The error message. /// The expression. /// /// The point in the expression at which the error was encountered. /// public BindingChainException(string message, string expression, string errorPoint) { _message = message; Expression = expression; ExpressionErrorPoint = errorPoint; } /// /// Gets the expression that could not be evaluated. /// public string? Expression { get; protected set; } /// /// Gets the point in the expression at which the error occurred. /// public string? ExpressionErrorPoint { get; protected set; } /// public override string Message { get { if (Expression != null && ExpressionErrorPoint != null) { return $"An error occured binding to '{Expression}' at '{ExpressionErrorPoint}': '{_message}'"; } else if (Expression != null) { return $"An error occured binding to '{Expression}': '{_message}'"; } else { return $"An error occured in a binding: '{_message}'"; } } } } }