Skip to content

Commit 28e14cc

Browse files
authored
Merge PR #248, Add generic decoding exception classes
1 parent 5578c8f commit 28e14cc

File tree

5 files changed

+146
-0
lines changed

5 files changed

+146
-0
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Text;
4+
5+
namespace ICSharpCode.SharpZipLib
6+
{
7+
/// <summary>
8+
/// Indicates that an error occured during decoding of a input stream due to corrupt
9+
/// data or (unintentional) library incompability.
10+
/// </summary>
11+
public class StreamDecodingException: SharpZipBaseException
12+
{
13+
private const string GenericMessage = "Input stream could not be decoded";
14+
15+
/// <summary>
16+
/// Initializes a new instance of the StreamDecodingException with a generic message
17+
/// </summary>
18+
public StreamDecodingException() : base(GenericMessage) { }
19+
20+
/// <summary>
21+
/// Initializes a new instance of the StreamDecodingException class with a specified error message.
22+
/// </summary>
23+
/// <param name="message">A message describing the exception.</param>
24+
public StreamDecodingException(string message) : base(message) { }
25+
26+
27+
/// <summary>
28+
/// Initializes a new instance of the StreamDecodingException class with a specified
29+
/// error message and a reference to the inner exception that is the cause of this exception.
30+
/// </summary>
31+
/// <param name="message">A message describing the exception.</param>
32+
/// <param name="innerException">The inner exception</param>
33+
public StreamDecodingException(string message, Exception innerException) : base(message, innerException) { }
34+
}
35+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
using System;
2+
3+
namespace ICSharpCode.SharpZipLib
4+
{
5+
/// <summary>
6+
/// Indicates that the input stream could not decoded due to known library incompability or missing features
7+
/// </summary>
8+
public class StreamUnsupportedException : StreamDecodingException
9+
{
10+
private const string GenericMessage = "Input stream is in a unsupported format";
11+
12+
/// <summary>
13+
/// Initializes a new instance of the StreamUnsupportedException with a generic message
14+
/// </summary>
15+
public StreamUnsupportedException() : base(GenericMessage) { }
16+
17+
/// <summary>
18+
/// Initializes a new instance of the StreamUnsupportedException class with a specified error message.
19+
/// </summary>
20+
/// <param name="message">A message describing the exception.</param>
21+
public StreamUnsupportedException(string message) : base(message) { }
22+
23+
24+
/// <summary>
25+
/// Initializes a new instance of the StreamUnsupportedException class with a specified
26+
/// error message and a reference to the inner exception that is the cause of this exception.
27+
/// </summary>
28+
/// <param name="message">A message describing the exception.</param>
29+
/// <param name="innerException">The inner exception</param>
30+
public StreamUnsupportedException(string message, Exception innerException) : base(message, innerException) { }
31+
32+
}
33+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
using System;
2+
3+
namespace ICSharpCode.SharpZipLib
4+
{
5+
/// <summary>
6+
/// Indicates that the input stream could not decoded due to the stream ending before enough data had been provided
7+
/// </summary>
8+
public class UnexpectedEndOfStreamException : StreamDecodingException
9+
{
10+
private const string GenericMessage = "Input stream ended unexpectedly";
11+
12+
/// <summary>
13+
/// Initializes a new instance of the UnexpectedEndOfStreamException with a generic message
14+
/// </summary>
15+
public UnexpectedEndOfStreamException() : base(GenericMessage) { }
16+
17+
/// <summary>
18+
/// Initializes a new instance of the UnexpectedEndOfStreamException class with a specified error message.
19+
/// </summary>
20+
/// <param name="message">A message describing the exception.</param>
21+
public UnexpectedEndOfStreamException(string message) : base(message) { }
22+
23+
24+
/// <summary>
25+
/// Initializes a new instance of the UnexpectedEndOfStreamException class with a specified
26+
/// error message and a reference to the inner exception that is the cause of this exception.
27+
/// </summary>
28+
/// <param name="message">A message describing the exception.</param>
29+
/// <param name="innerException">The inner exception</param>
30+
public UnexpectedEndOfStreamException(string message, Exception innerException) : base(message, innerException) { }
31+
32+
}
33+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Text;
4+
5+
namespace ICSharpCode.SharpZipLib
6+
{
7+
8+
/// <summary>
9+
/// Indicates that a value was outside of the expected range when decoding an input stream
10+
/// </summary>
11+
public class ValueOutOfRangeException : StreamDecodingException
12+
{
13+
/// <summary>
14+
/// Initializes a new instance of the ValueOutOfRangeException class naming the the causing variable
15+
/// </summary>
16+
/// <param name="nameOfValue">Name of the variable, use: nameof()</param>
17+
public ValueOutOfRangeException(string nameOfValue )
18+
: base($"{nameOfValue} out of range") { }
19+
20+
/// <summary>
21+
/// Initializes a new instance of the ValueOutOfRangeException class naming the the causing variable,
22+
/// it's current value and expected range.
23+
/// </summary>
24+
/// <param name="nameOfValue">Name of the variable, use: nameof()</param>
25+
/// <param name="value">The invalid value</param>
26+
/// <param name="maxValue">Expected maximum value</param>
27+
/// <param name="minValue">Expected minimum value</param>
28+
public ValueOutOfRangeException(string nameOfValue, long value, long maxValue, long minValue = 0)
29+
: this(nameOfValue, value.ToString(), maxValue.ToString(), minValue.ToString()) { }
30+
31+
/// <summary>
32+
/// Initializes a new instance of the ValueOutOfRangeException class naming the the causing variable,
33+
/// it's current value and expected range.
34+
/// </summary>
35+
/// <param name="nameOfValue">Name of the variable, use: nameof()</param>
36+
/// <param name="value">The invalid value</param>
37+
/// <param name="maxValue">Expected maximum value</param>
38+
/// <param name="minValue">Expected minimum value</param>
39+
public ValueOutOfRangeException(string nameOfValue, string value, string maxValue, string minValue = "0") :
40+
base($"{nameOfValue} out of range: {value}, should be {minValue}..{maxValue}") { }
41+
42+
private ValueOutOfRangeException() { }
43+
private ValueOutOfRangeException(string message, Exception innerException) : base(message, innerException) {}
44+
}
45+
}

0 commit comments

Comments
 (0)