Table of Contents

Class UnicodeTranslateError

Namespace
NumSharp
Assembly
NumSharp.dll

Python's UnicodeTranslateError: a character str.translate-style mapping could not translate (can't translate character '\xe9' in position 1: reason).

public class UnicodeTranslateError : UnicodeError, ISerializable, INumSharpException
Inheritance
UnicodeTranslateError
Implements
Inherited Members

Remarks

A subclass of UnicodeError and so of ValueError, as in Python. Like UnicodeEncodeError it carries object, start, end and reason; its encoding is always null, as Python's is None (a translation has no codec).

NumSharp never raises it (np.strings.translate maps through a table that cannot fail); the class exists so a port of code that raises or catches it compiles and behaves as in Python.

Constructors

UnicodeTranslateError(string)

Creates the error from a message alone: object and reason are null and start / end are 0, as for UnicodeEncodeError(string).

public UnicodeTranslateError(string message)

Parameters

message string

The verbatim message.

Remarks

Python has no such constructor (its UnicodeTranslateError takes the four arguments); this form is for code that holds a text only.

UnicodeTranslateError(string, Exception)

Creates the error from a message and the exception that caused it (Python's raise ... from innerException), .NET's standard constructor every NumSharp exception has: like the message-only form, object and reason are null and start / end are 0.

public UnicodeTranslateError(string message, Exception innerException)

Parameters

message string

The verbatim message.

innerException Exception

The exception that led to this one, or null for none.

Remarks

Prefer the four-argument form when the untranslatable position is known, so a caller can read it without parsing the message.

UnicodeTranslateError(string, long, long, string)

Python's UnicodeTranslateError(object, start, end, reason): the message is CPython's UnicodeTranslateError.str of the four values.

public UnicodeTranslateError(string @object, long start, long end, string reason)

Parameters

object string

The text being translated.

start long

The code-point position of the first untranslatable character.

end long

One past the last one.

reason string

The reason text.

Remarks

The one-character message (end == start + 1, start inside the text) quotes the code point at start escaped, as CPython prints it: '\xe9', '\u4e2d', '\U0001f600'; any other range reads characters in position 0-1, the bounds as given (CPython does not clamp them). Footgun, as for UnicodeEncodeError: start and end count code points, not UTF-16 units.

Exceptions

TypeError

object or reason is null (CPython: argument 1 must be str, not None, argument 4 must be str, not None).

Properties

encoding

Always null: a translation names no codec (Python's encoding is None).

public string encoding { get; }

Property Value

string

end

One past the code-point position of the last one (Python's end); 0 when the error was built from a message.

public long end { get; }

Property Value

long

object

The text being translated (Python's object); null when the error was built from a message.

public string @object { get; }

Property Value

string

reason

The reason text (Python's reason); null when the error was built from a message.

public string reason { get; }

Property Value

string

start

The code-point position of the first untranslatable character (Python's start); 0 when the error was built from a message.

public long start { get; }

Property Value

long