using System;
namespace MathInterpreter.Core;
public abstract class ExpressionException : Exception
{
///
/// Initializes with the specified error and the optional
///
/// The error message
/// The optional exception
protected ExpressionException(string message, Exception? innerException = null)
: base(message, innerException) { }
}
public sealed class ExpressionFormatException : ExpressionException
{
///
/// Initializes with the specified error and the optional
///
/// The error message
/// The innerException
public ExpressionFormatException(string message, Exception? innerException = null)
: base(message, innerException) { }
}
public sealed class OperatorException : ExpressionException
{
///
/// Initializes with the specified error
///
/// The error message
public OperatorException(string message) : base(message) { }
}
public sealed class NumberFormatException : ExpressionException
{
///
/// Initializes with the and the optional
///
/// The expression
/// The optional reason
public NumberFormatException(ReadOnlySpan expression, string? reason = null)
: base(FormatMessage(expression, reason)) { }
private static string FormatMessage(ReadOnlySpan expression, string? reason = null)
{
reason = string.IsNullOrWhiteSpace(reason) ? string.Empty : $" ({reason})";
return $"Unable to read number from beginning of '{expression}'{reason}";
}
}
public sealed class NumberValueException : ExpressionException
{
///
/// Initializes with the specified error
///
/// The error message
public NumberValueException(string message) : base(message) { }
}