EncoderFallbackException Sınıf
Tanım
Önemli
Bazı bilgiler ürünün ön sürümüyle ilgilidir ve sürüm öncesinde önemli değişiklikler yapılmış olabilir. Burada verilen bilgilerle ilgili olarak Microsoft açık veya zımni hiçbir garanti vermez.
Kodlayıcı geri dönüş işlemi başarısız olduğunda oluşan özel durum. Bu sınıf devralınamaz.
public ref class EncoderFallbackException sealed : ArgumentException
public sealed class EncoderFallbackException : ArgumentException
[System.Serializable]
public sealed class EncoderFallbackException : ArgumentException
type EncoderFallbackException = class
inherit ArgumentException
[<System.Serializable>]
type EncoderFallbackException = class
inherit ArgumentException
Public NotInheritable Class EncoderFallbackException
Inherits ArgumentException
- Devralma
- Devralma
- Öznitelikler
Örnekler
Aşağıdaki kod örneği ve EncoderExceptionFallback sınıflarını EncoderFallbackException gösterir.
// This example demonstrates the EncoderExceptionFallback class.
using System;
using System.Text;
class Sample
{
public static void Main()
{
// Create an encoding, which is equivalent to calling the
// ASCIIEncoding class constructor.
// The EncoderExceptionFallback parameter causes an exception to
// be thrown when a character cannot be encoded.
// A decoder exception fallback is also specified, but it is not
// used because this example terminates during the encoding operation.
Encoding ae = Encoding.GetEncoding(
"us-ascii",
new EncoderExceptionFallback(),
new DecoderExceptionFallback());
// The input string consists of the Unicode characters LEFT POINTING
// DOUBLE ANGLE QUOTATION MARK (U+00AB), 'X' (U+0058), and RIGHT POINTING
// DOUBLE ANGLE QUOTATION MARK (U+00BB).
// The encoding can only encode characters in the US-ASCII range of U+0000
// through U+007F. Consequently, the characters bracketing the 'X' character
// cause an exception.
string inputString = "\u00abX\u00bb";
string twoNewLines = "\n\n";
byte[] encodedBytes = new byte[ae.GetMaxByteCount(inputString.Length)];
int numberOfEncodedBytes = 0;
// --------------------------------------------------------------------------
Console.Clear();
// Display the name of the encoding.
Console.WriteLine("The name of the encoding is \"{0}\".\n", ae.WebName);
// Display the input string in text.
Console.WriteLine("Input string ({0} characters): \"{1}\"",
inputString.Length, inputString);
// Display the input string in hexadecimal.
Console.Write("Input string in hexadecimal: ");
foreach (char c in inputString.ToCharArray()) {
Console.Write("0x{0:X2} ", (int)c);}
Console.Write(twoNewLines);
// --------------------------------------------------------------------------
// Attempt to encode the input string. However, an exception is thrown before
// the input string can be encoded.
Console.WriteLine("Encode the input string...");
// The code example terminates during the call to the GetBytes() method.
try {
numberOfEncodedBytes = ae.GetBytes(inputString, 0, inputString.Length,
encodedBytes, 0);
}
catch (EncoderFallbackException e)
{
Console.WriteLine(e);
Console.WriteLine("\n*** THE CODE EXAMPLE TERMINATES HERE AS INTENDED. ***");
return;
}
// This statement is never executed.
Console.WriteLine("This statement is never executed.");
}
}
/*
This code example produces the following results:
The name of the encoding is "us-ascii".
Input string (3 characters): "«X»"
Input string in hexadecimal: 0xAB 0x58 0xBB
Encode the input string...
System.Text.EncoderFallbackException: Unable to translate Unicode character \u00AB at inde
x 0 to specified code page.
at System.Text.EncoderExceptionFallbackBuffer.Fallback(Char charUnknown, Int32 index)
at System.Text.EncoderFallbackBuffer.InternalFallback(Char ch, Char*& chars)
at System.Text.ASCIIEncoding.GetBytes(Char* chars, Int32 charCount, Byte* bytes, Int32
byteCount, EncoderNLS encoder)
at System.Text.ASCIIEncoding.GetBytes(String chars, Int32 charIndex, Int32 charCount, B
yte[] bytes, Int32 byteIndex)
at Sample.Main()
*** THE CODE EXAMPLE TERMINATES HERE AS INTENDED. ***
*/
' This example demonstrates the EncoderExceptionFallback class.
Imports System.Text
Class Sample
Public Shared Sub Main()
' Create an encoding, which is equivalent to calling the
' ASCIIEncoding class constructor.
' The EncoderExceptionFallback parameter causes an exception to
' be thrown when a character cannot be encoded.
' A decoder exception fallback is also specified, but it is not
' used because this example terminates during the encoding operation.
Dim eef As New EncoderExceptionFallback()
Dim def As New DecoderExceptionFallback()
Dim ae As Encoding = Encoding.GetEncoding("us-ascii", eef, def)
' The input string consists of the Unicode characters LEFT POINTING
' DOUBLE ANGLE QUOTATION MARK (U+00AB), 'X' (U+0058), and RIGHT POINTING
' DOUBLE ANGLE QUOTATION MARK (U+00BB).
' The encoding can only encode characters in the US-ASCII range of U+0000
' through U+007F. Consequently, the characters bracketing the 'X' character
' cause an exception.
Dim inputString As String = "«X»"
Dim twoNewLines As String = vbCrLf & vbCrLf
Dim numberOfEncodedBytes As Integer = ae.GetMaxByteCount(inputString.Length)
' Counteract the compiler adding an extra element.
Dim encodedBytes(numberOfEncodedBytes - 1) As Byte
' --------------------------------------------------------------------------
Console.Clear()
' Display the name of the encoding.
Console.WriteLine("The name of the encoding is ""{0}""." & vbCrLf, ae.WebName)
' Display the input string in text.
Console.WriteLine("Input string ({0} characters): ""{1}""", _
inputString.Length, inputString)
' Display the input string in hexadecimal.
' Each element is converted to an integer with Convert.ToInt32.
Console.Write("Input string in hexadecimal: ")
Dim c As Char
For Each c In inputString.ToCharArray()
Console.Write("0x{0:X2} ", Convert.ToInt32(c))
Next c
Console.Write(twoNewLines)
' --------------------------------------------------------------------------
' Attempt to encode the input string. However, an exception is thrown before
' the input string can be encoded.
Console.WriteLine("Encode the input string...")
' The code example terminates during the call to the GetBytes() method.
Try
numberOfEncodedBytes = ae.GetBytes(inputString, 0, inputString.Length, _
encodedBytes, 0)
Catch e As EncoderFallbackException
Console.WriteLine(e)
Console.WriteLine(vbCrLf & _
"*** THE CODE EXAMPLE TERMINATES HERE AS INTENDED. ***")
Return
End Try
' This statement is never executed.
Console.WriteLine("This statement is never executed.")
End Sub
End Class
'
'This code example produces the following results:
'
'The name of the encoding is "us-ascii".
'
'Input string (3 characters): "X"
'Input string in hexadecimal: 0xAB 0x58 0xBB
'
'Encode the input string...
'System.Text.EncoderFallbackException: Unable to translate Unicode character \u00AB at inde
'x 0 to specified code page.
' at System.Text.EncoderExceptionFallbackBuffer.Fallback(Char charUnknown, Int32 index)
' at System.Text.EncoderFallbackBuffer.InternalFallback(Char ch, Char*& chars)
' at System.Text.ASCIIEncoding.GetBytes(Char* chars, Int32 charCount, Byte* bytes, Int32
'byteCount, EncoderNLS encoder)
' at System.Text.ASCIIEncoding.GetBytes(String chars, Int32 charIndex, Int32 charCount, B
'yte[] bytes, Int32 byteIndex)
' at Sample.Main()
'
'*** THE CODE EXAMPLE TERMINATES HERE AS INTENDED. ***
'
Oluşturucular
| Name | Description |
|---|---|
| EncoderFallbackException() |
EncoderFallbackException sınıfının yeni bir örneğini başlatır. |
| EncoderFallbackException(String, Exception) |
EncoderFallbackException sınıfının yeni bir örneğini başlatır. Parametreler hata iletisini ve bu özel durumun nedeni olan iç özel durumu belirtir. |
| EncoderFallbackException(String) |
EncoderFallbackException sınıfının yeni bir örneğini başlatır. Parametre hata iletisini belirtir. |
Özellikler
| Name | Description |
|---|---|
| CharUnknown |
Özel duruma neden olan giriş karakterini alır. |
| CharUnknownHigh |
Özel duruma neden olan vekil çiftin yüksek bileşen karakterini alır. |
| CharUnknownLow |
Özel duruma neden olan vekil çiftin düşük bileşen karakterini alır. |
| Data |
Özel durum hakkında kullanıcı tanımlı ek bilgiler sağlayan anahtar/değer çiftleri koleksiyonunu alır. (Devralındığı yer: Exception) |
| HelpLink |
Bu özel durumla ilişkili yardım dosyasının bağlantısını alır veya ayarlar. (Devralındığı yer: Exception) |
| HResult |
Belirli bir özel duruma atanan kodlanmış sayısal bir değer olan HRESULT değerini alır veya ayarlar. (Devralındığı yer: Exception) |
| Index |
Özel duruma neden olan karakterin giriş arabelleğinde dizin konumunu alır. |
| InnerException |
Geçerli özel duruma neden olan Exception örneğini alır. (Devralındığı yer: Exception) |
| Message |
Hata iletisini ve parametre adını veya yalnızca parametre adı ayarlanmadıysa hata iletisini alır. (Devralındığı yer: ArgumentException) |
| ParamName |
Bu özel duruma neden olan parametrenin adını alır. (Devralındığı yer: ArgumentException) |
| Source |
Hataya neden olan uygulamanın veya nesnenin adını alır veya ayarlar. (Devralındığı yer: Exception) |
| StackTrace |
Çağrı yığınındaki anlık çerçevelerin dize gösterimini alır. (Devralındığı yer: Exception) |
| TargetSite |
Geçerli özel durumu oluşturan yöntemini alır. (Devralındığı yer: Exception) |
Yöntemler
| Name | Description |
|---|---|
| Equals(Object) |
Belirtilen nesnenin geçerli nesneye eşit olup olmadığını belirler. (Devralındığı yer: Object) |
| GetBaseException() |
Türetilmiş bir sınıfta geçersiz kılındığında, sonraki bir veya daha fazla özel durumun kök nedeni olan Exception döndürür. (Devralındığı yer: Exception) |
| GetHashCode() |
Varsayılan karma işlevi işlevi görür. (Devralındığı yer: Object) |
| GetObjectData(SerializationInfo, StreamingContext) |
Geçersiz.
SerializationInfo Nesnesini parametre adı ve ek özel durum bilgileriyle ayarlar. (Devralındığı yer: ArgumentException) |
| GetType() |
Geçerli örneğin çalışma zamanı türünü alır. (Devralındığı yer: Exception) |
| IsUnknownSurrogate() |
Özel duruma neden olan girişin vekil çift olup olmadığını gösterir. |
| MemberwiseClone() |
Geçerli Objectbasit bir kopyasını oluşturur. (Devralındığı yer: Object) |
| ToString() |
Geçerli özel durumun dize gösterimini oluşturur ve döndürür. (Devralındığı yer: Exception) |
Ekinlikler
| Name | Description |
|---|---|
| SerializeObjectState |
Geçersiz.
Özel durum hakkında serileştirilmiş veriler içeren bir özel durum durumu nesnesi oluşturmak için bir özel durum seri hale getirildiğinde gerçekleşir. (Devralındığı yer: Exception) |