using System; using System.Runtime.Serialization; namespace ICSharpCode.SharpZipLib { /// /// Indicates that a value was outside of the expected range when decoding an input stream /// [Serializable] public class ValueOutOfRangeException : StreamDecodingException { /// /// Initializes a new instance of the ValueOutOfRangeException class naming the causing variable /// /// Name of the variable, use: nameof() public ValueOutOfRangeException(string nameOfValue) : base($"{nameOfValue} out of range") { } /// /// Initializes a new instance of the ValueOutOfRangeException class naming the causing variable, /// it's current value and expected range. /// /// Name of the variable, use: nameof() /// The invalid value /// Expected maximum value /// Expected minimum value public ValueOutOfRangeException(string nameOfValue, long value, long maxValue, long minValue = 0) : this(nameOfValue, value.ToString(), maxValue.ToString(), minValue.ToString()) { } /// /// Initializes a new instance of the ValueOutOfRangeException class naming the causing variable, /// it's current value and expected range. /// /// Name of the variable, use: nameof() /// The invalid value /// Expected maximum value /// Expected minimum value public ValueOutOfRangeException(string nameOfValue, string value, string maxValue, string minValue = "0") : base($"{nameOfValue} out of range: {value}, should be {minValue}..{maxValue}") { } private ValueOutOfRangeException() { } private ValueOutOfRangeException(string message, Exception innerException) : base(message, innerException) { } /// /// Initializes a new instance of the ValueOutOfRangeException class with serialized data. /// /// /// The System.Runtime.Serialization.SerializationInfo that holds the serialized /// object data about the exception being thrown. /// /// /// The System.Runtime.Serialization.StreamingContext that contains contextual information /// about the source or destination. /// protected ValueOutOfRangeException(SerializationInfo info, StreamingContext context) : base(info, context) { } } }