Table of Contents

BencodeFormatException Class

Definition

Namespace
Bodu.Text.Bencode
Assembly
Bodu.Text.Bencode.dll
Package
Bodu.Text.Bencode 1.0.0
Source
BencodeFormatException.cs

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

message string

The error message.

BencodeFormatException(string, Exception)

Initializes a new instance of the BencodeFormatException class.

public BencodeFormatException(string message, Exception innerException)

Parameters

message string

The error message.

innerException Exception

The inner exception.

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

message string

The error message.

offset int

The zero-based byte offset from the start of the source.

Properties

Offset

Gets the zero-based byte offset at which the parse error was detected, when available.

public int? Offset { get; }

Property Value

int?

The byte offset, or null when no position is associated with the error.

Applies to

ProductVersions
.NET8, 10