BencodeFormatException Class
Definition
- Assembly
- Bodu.Text.Bencode.dll
- Package
- Bodu.Text.Bencode 1.0.0
Represents an error that occurs when bencoded data is malformed.
public sealed class BencodeFormatException : FormatException, ISerializable
- Inheritance
-
BencodeFormatException
- Implements
- Inherited Members
- Extension Methods
Examples
try
{
TorrentInfo info = BencodeSerializer.Deserialize<TorrentInfo>(payload);
}
catch (BencodeFormatException ex)
{
Console.Error.WriteLine($"Malformed bencode at byte {ex.Offset}: {ex.Message}");
}
Remarks
Raised by Read() - and therefore surfaced by BencodeSerializer while
deserializing - when the input cannot be interpreted as a valid bencoded document: for example, when an unexpected
prefix byte is encountered, an integer is missing its terminating e, a string's length prefix does not fit
the remaining bytes, a dictionary's keys are not in lexicographic order, or the document contains trailing bytes
after a complete value.
Malformed input and binding failures are reported separately: catch BencodeFormatException (a FormatException ) for bytes that are not valid Bencode, and BencodeSerializationException for values or documents that cannot be mapped; catch both when the handling should not distinguish the cause.
Constructors
BencodeFormatException()
Initializes a new instance of the BencodeFormatException class.
public BencodeFormatException()
BencodeFormatException(string)
Initializes a new instance of the BencodeFormatException class.
public BencodeFormatException(string message)
Parameters
messagestringThe error message.
BencodeFormatException(string, Exception)
Initializes a new instance of the BencodeFormatException class.
public BencodeFormatException(string message, Exception innerException)
Parameters
BencodeFormatException(string, int)
Initializes a new instance of the BencodeFormatException class and records the byte offset at which the parse error was detected.
public BencodeFormatException(string message, int offset)
Parameters
Properties
Offset
Gets the zero-based byte offset at which the parse error was detected, when available.
public int? Offset { get; }
Property Value
Applies to
| Product | Versions |
|---|---|
| .NET | 8, 10 |