FormatException FormatException FormatException FormatException Class

定义

当自变量的格式无效或复合格式字符串的格式不标准时引发的异常。The exception that is thrown when the format of an argument is invalid, or when a composite format string is not well formed.

public ref class FormatException : SystemException
[System.Runtime.InteropServices.ComVisible(true)]
[System.Serializable]
public class FormatException : SystemException
type FormatException = class
    inherit SystemException
Public Class FormatException
Inherits SystemException
继承
派生
属性

注解

由于以下原因之一, 可能会引发异常:FormatExceptionA FormatException exception can be thrown for one of the following reasons:

  • 在对将字符串转换为其他数据类型的方法的调用中, 该字符串不符合所需模式。In a call to a method that converts a string to some other data type, the string doesn't conform to the required pattern. 这通常发生在调用Convert类的某些方法和某些类型的ParseExact Parse和方法时。This typically occurs when calling some methods of the Convert class and the Parse and ParseExact methods of some types.

    在大多数情况下, 特别是当要转换的字符串是用户输入或从文件中读取时, 应使用try/catch块并FormatException处理异常 (如果转换不成功)。In most cases, particularly if the string that you're converting is input by a user or read from a file, you should use a try/catch block and handle the FormatException exception if the conversion is unsuccessful. 你还可以将对转换方法的调用替换为对TryParseTryParseExact方法的调用 (如果存在)。You can also replace the call to the conversion method with a call to a TryParse or TryParseExact method, if one exists. 但是, FormatException当你尝试分析预定义或硬编码字符串时引发的异常指示程序错误。However, a FormatException exception that is thrown when you're trying to parse a predefined or hard-coded string indicates a program error. 在这种情况下, 应更正此错误, 而不是处理异常。In this case, you should correct the error rather than handle the exception.

    将字符串转换为System命名空间中的以下类型可能会FormatException引发异常:The conversion of a string to the following types in the System namespace can throw a FormatException exception:

    • BooleanBoolean. Boolean.Parse(String)Convert.ToBoolean(String)方法要求将字符串转换为 "true"、"true"、"false" 或 "false"。The Boolean.Parse(String) and Convert.ToBoolean(String) methods require the string to be converted to be "True", "true", "False", or "false". 任何其他值都将FormatException引发异常。Any other value throws a FormatException exception.

    • DateTimeDateTimeOffsetDateTime and DateTimeOffset. 所有日期和时间数据都基于特定区域性的格式设置约定: 当前线程区域性 (或在某些情况下为当前应用程序域区域性)、固定区域性或指定的区域性。All date and time data is interpreted based on the formatting conventions of a particular culture: either the current thread culture (or, in some cases, the current application domain culture), the invariant culture, or a specified culture. 在调用DateTime.ParseExact(String, String, IFormatProvider, DateTimeStyles) DateTimeOffset.ParseExact(String, String[], IFormatProvider, DateTimeStyles)和方法时, 日期和时间数据还必须完全符合由一个或多个标准格式字符串自定义格式字符串(作为中的参数提供) 指定的模式方法调用。When you call the DateTime.ParseExact(String, String, IFormatProvider, DateTimeStyles) and DateTimeOffset.ParseExact(String, String[], IFormatProvider, DateTimeStyles) methods, date and time data must also conform exactly to a pattern specified by one or more standard format strings or custom format strings that are provided as arguments in the method call. 如果它不符合预期的区域性特定模式, FormatException则会引发异常。If it doesn't conform to an expected culture-specific pattern, a FormatException exception is thrown. 这意味着, 在一个系统上保存为特定于区域性的格式的日期和时间数据可能无法在其他系统上成功分析。This means that date and time data saved in a culture-specific format on one system might not parse successfully on another system.

      有关分析日期和时间的详细信息, 请参阅分析日期和时间字符串和引发异常的方法的文档。For more information about parsing dates and times, see Parsing Date and Time Strings and the documentation for the method that threw the exception.

    • Guid.GUIDs. GUID 的字符串表示形式必须包含32个十六进制数字 (0-F), 并且必须是由Guid.ToString方法输出的五种格式中的一种。The string representation of a GUID must consist of 32 hexadecimal digits (0-F), and must be in one of the five formats output by the Guid.ToString method. 有关更多信息,请参见 Guid.Parse 方法。For more information, see the Guid.Parse method.

    • 数值类型, 包括所有有符号整数、无符号整数和浮点类型。Numeric types, including all signed integers, unsigned integers, and floating-point types. 要分析的字符串必须包含拉丁语位数0-9。The string to be parsed must consist of the Latin digits 0-9. 还可以允许使用正号或负号、小数点分隔符、组分隔符和货币符号。A positive or negative sign, decimal separator, group separators, and currency symbol may also be permitted. 尝试分析包含任何其他字符的字符串始终会引发FormatException异常。Trying to parse a string that contains any other character always throws a FormatException exception.

      所有数字字符串都基于特定区域性的格式设置约定: 当前线程区域性 (或在某些情况下为当前应用程序域区域性)、固定区域性或指定的区域性。All numeric strings are interpreted based on the formatting conventions of a particular culture: either the current thread culture (or, in some cases, the current application domain culture), the invariant culture, or a specified culture. 因此, 使用另一种区域性的约定分析的数值字符串可能会失败。As a result, a numeric string that is parsed by using the conventions of one culture might fail when using the conventions of another.

      有关分析数值字符串的详细信息, 请参阅分析数值字符串和引发异常的特定方法的文档。For more information about parsing numeric strings, see Parsing Numeric Strings and the documentation for the specific method that threw the exception.

    • 时间间隔。Time intervals. 要分析的字符串必须是采用不区分区域性的格式或由当前线程区域性定义的区分区域性的格式 (在某些情况下为当前应用程序域区域性)、固定区域性或指定的区域性。The string to be parsed must be either in fixed culture-insensitive format or in a culture-sensitive format defined by the current thread culture (or, in some cases, the current application domain culture), the invariant culture, or a specified culture. 如果字符串的格式不正确, 或者如果时间间隔的最小值、天数、小时数和分钟数部分不存在, 分析方法将引发FormatException异常。If the string isn't in an appropriate format, or if, at the minimum, the days, hours, and minutes components of the time interval aren't present, the parsing method throws a FormatException exception. 有关详细信息, 请参阅引发异常的TimeSpan分析方法的文档。For more information, see the documentation for the TimeSpan parsing method that threw the exception.

  • 类型实现IFormattable接口, 该接口支持定义如何将对象转换为其字符串表示形式, 并使用无效格式字符串的格式字符串。A type implements the IFormattable interface, which supports format strings that define how an object is converted to its string representation, and an invalid format string is used. 这在格式设置操作中最常见。This is most common in a formatting operation. 在下面的示例中, 在复合格式字符串中使用 "Q" 标准格式字符串来设置数值的格式。In the following example, the "Q" standard format string is used in a composite format string to format a number. 但是, "Q" 不是有效的标准格式字符串However, "Q" is not a valid standard format string.

    using System;
    
    public class Example
    {
       public static void Main()
       {
          decimal price = 169.32m;
          Console.WriteLine("The cost is {0:Q2}.", price);
       }
    }
    // The example displays the following output:
    //    Unhandled Exception: System.FormatException: Format specifier was invalid.
    //       at System.Number.FormatDecimal(Decimal value, String format, NumberFormatInfo info)
    //       at System.Decimal.ToString(String format, IFormatProvider provider)
    //       at System.Text.StringBuilder.AppendFormat(IFormatProvider provider, String format, Object[] args)
    //       at System.IO.TextWriter.WriteLine(String format, Object arg0)
    //       at System.IO.TextWriter.SyncTextWriter.WriteLine(String format, Object arg0)
    //       at Example.Main()
    
    Module Example
       Public Sub Main()
          Dim price As Decimal = 169.32d
          Console.WriteLine("The cost is {0:Q2}.", price)
       End Sub
    End Module
    ' The example displays the following output:
    '    Unhandled Exception: System.FormatException: Format specifier was invalid.
    '       at System.Number.FormatDecimal(Decimal value, String format, NumberFormatInfo info)
    '       at System.Decimal.ToString(String format, IFormatProvider provider)
    '       at System.Text.StringBuilder.AppendFormat(IFormatProvider provider, String format, Object[] args)
    '       at System.IO.TextWriter.WriteLine(String format, Object arg0)
    '       at System.IO.TextWriter.SyncTextWriter.WriteLine(String format, Object arg0)
    '       at Example.Main()
    

    此异常是由编码错误引起的。This exception results from a coding error. 若要更正此错误, 请删除格式字符串或替换有效的字符串。To correct the error, either remove the format string or substitute a valid one. 下面的示例通过使用 "C" (货币) 格式字符串替换无效的格式字符串来纠正错误。The following example corrects the error by replacing the invalid format string with the "C" (currency) format string.

    using System;
    
    public class Example
    {
       public static void Main()
       {
          decimal price = 169.32m;
          Console.WriteLine("The cost is {0:C2}.", price);
       }
    }
    // The example displays the following output:
    //    The cost is $169.32.
    
    Module Example
       Public Sub Main()
          Dim price As Decimal = 169.32d
          Console.WriteLine("The cost is {0:C2}.", price)
       End Sub
    End Module
    ' The example displays the following output:
    '   The cost is $169.32.
    

    还可以通过分析方法 ( DateTime.ParseExact如和Guid.ParseExact) 引发异常,这需要对字符串进行分析,使其符合格式字符串指定的模式。FormatExceptionA FormatException exception can also be thrown by parsing methods, such as DateTime.ParseExact and Guid.ParseExact, that require the string to be parsed to conform exactly to the pattern specified by a format string. 在下面的示例中, GUID 的字符串表示形式应符合 "G" 标准格式字符串指定的模式。In the following example, the string representation of a GUID is expected to conform to the pattern specified by the "G" standard format string. 但是, Guid结构的IFormattable实现不支持 "G" 格式字符串。However, the Guid structure's implementation of IFormattable does not support the "G" format string.

    using System;
    
    public class Example
    {
       public static void Main()
       {
          string guidString = "ba748d5c-ae5f-4cca-84e5-1ac5291c38cb";
          Console.WriteLine(Guid.ParseExact(guidString, "G"));
       }
    }
    // The example displays the following output:
    //    Unhandled Exception: System.FormatException: 
    //       Format String can be only "D", "d", "N", "n", "P", "p", "B", "b", "X" or "x".
    //       at System.Guid.ParseExact(String input, String format)
    //       at Example.Main()
    
    Module Example
       Public Sub Main()
          Dim guidString As String = "ba748d5c-ae5f-4cca-84e5-1ac5291c38cb"
          Console.WriteLine(Guid.ParseExact(guidString, "G"))
       End Sub
    End Module
    ' The example displays the following output:
    '    Unhandled Exception: System.FormatException: 
    '       Format String can be only "D", "d", "N", "n", "P", "p", "B", "b", "X" or "x".
    '       at System.Guid.ParseExact(String input, String format)
    '       at Example.Main()
    

    此异常也是由于编码错误引起的。This exception also results from a coding error. 若要更正此错误, 请调用不需要精确格式的分析方法 (如DateTime.ParseGuid.Parse) 或替换有效的格式字符串。To correct it, call a parsing method that doesn't require a precise format, such as DateTime.Parse or Guid.Parse, or substitute a valid format string. 下面的示例通过调用Guid.Parse方法来更正错误。The following example corrects the error by calling the Guid.Parse method.

    using System;
    
    public class Example
    {
       public static void Main()
       {
          string guidString = "ba748d5c-ae5f-4cca-84e5-1ac5291c38cb";
          Console.WriteLine(Guid.Parse(guidString));
       }
    }
    // The example displays the following output:
    //    ba748d5c-ae5f-4cca-84e5-1ac5291c38cb
    
    Module Example
       Public Sub Main()
          Dim guidString As String = "ba748d5c-ae5f-4cca-84e5-1ac5291c38cb"
          Console.WriteLine(Guid.Parse(guidString))
       End Sub
    End Module
    ' The example displays the following output:
    '   ba748d5c-ae5f-4cca-84e5-1ac5291c38cb
    
  • 复合格式字符串中的格式项的一个或多个索引大于对象列表或参数数组中项的索引。One or more of the indexes of the format items in a composite format string is greater than the indexes of the items in the object list or parameter array. 在下面的示例中, 格式字符串中的格式项的最大索引为3。In the following example, the largest index of a format item in the format string is 3. 由于对象列表中项的索引是从零开始的, 因此此格式字符串要求对象列表具有四项。Because the indexes of items in the object list are zero-based, this format string would require the object list to have four items. 相反, 它只有三个、 dat temp、和scale, 因此, 代码会在运行时FormatException导致异常:。Instead, it has only three, dat, temp, and scale, so the code results in a FormatException exception at run time:.

    using System;
    
    public class Example
    {
       public enum TemperatureScale 
       { Celsius, Fahrenheit, Kelvin }
    
       public static void Main()
       {
          String info = GetCurrentTemperature();
          Console.WriteLine(info);
       }
    
       private static String GetCurrentTemperature()
       {
          DateTime dat = DateTime.Now;
          Decimal temp = 20.6m;
          TemperatureScale scale = TemperatureScale.Celsius;
          String result;
          
          result = String.Format("At {0:t} on {1:D}, the temperature is {2:F1} {3:G}",
                                 dat, temp, scale);    
          return result;
       }
    }
    // The example displays output like the following:
    //    Unhandled Exception: System.FormatException: Format specifier was invalid.
    //       at System.Number.FormatDecimal(Decimal value, String format, NumberFormatInfo info)
    //       at System.Decimal.ToString(String format, IFormatProvider provider)
    //       at System.Text.StringBuilder.AppendFormat(IFormatProvider provider, String format, Object[] args)
    //       at System.String.Format(IFormatProvider provider, String format, Object[] args)
    //       at Example.Main()
    
    Module Example
       Public Enum TemperatureScale As Integer
          Celsius
          Fahrenheit
          Kelvin
       End Enum
    
       Public Sub Main()
          Dim info As String = GetCurrentTemperature()
          Console.WriteLine(info)
       End Sub
    
       Private Function GetCurrentTemperature() As String
          Dim dat As Date = Date.Now
          Dim temp As Decimal = 20.6d
          Dim scale As TemperatureScale = TemperatureScale.Celsius
          Dim result As String 
          
          result = String.Format("At {0:t} on {1:D}, the temperature is {2:F1} {3:G}",
                                 dat, temp, scale)    
          Return result
       End Function
    End Module
    ' The example displays output like the following:
    '    Unhandled Exception: System.FormatException: Format specifier was invalid.
    '       at System.Number.FormatDecimal(Decimal value, String format, NumberFormatInfo info)
    '       at System.Decimal.ToString(String format, IFormatProvider provider)
    '       at System.Text.StringBuilder.AppendFormat(IFormatProvider provider, String format, Object[] args)
    '       at System.String.Format(IFormatProvider provider, String format, Object[] args)
    '       at Example.Main()
    

    在这种情况下FormatException , 异常是由开发人员错误引起的。In this case, the FormatException exception is a result of developer error. 应更正此情况, 而不是通过try/catch确保对象列表中的每个项对应于格式项的索引, 而不是在块中进行处理。It should be corrected rather than handled in a try/catch block by making sure that each item in the object list corresponds to the index of a format item. 若要更正此示例, 请将第二个格式项的索引改为dat引用变量, 并将每个后续格式项的索引减一。To correct this example, change the index of the second format item to refer to the dat variable, and decrement the index of each subsequent format item by one.

    using System;
    
    public class Example
    {
       public enum TemperatureScale 
       { Celsius, Fahrenheit, Kelvin }
    
       public static void Main()
       {
          String info = GetCurrentTemperature();
          Console.WriteLine(info);
       }
    
       private static String GetCurrentTemperature()
       {
          DateTime dat = DateTime.Now;
          Decimal temp = 20.6m;
          TemperatureScale scale = TemperatureScale.Celsius;
          String result;
          
          result = String.Format("At {0:t} on {0:D}, the temperature is {1:F1} {2:G}",
                                 dat, temp, scale);    
          return result;
       }
    }
    // The example displays output like the following:
    //    At 10:40 AM on Wednesday, June 04, 2014, the temperature is 20.6 Celsius
    
    Module Example
       Public Enum TemperatureScale As Integer
          Celsius
          Fahrenheit
          Kelvin
       End Enum
    
       Public Sub Main()
          Dim info As String = GetCurrentTemperature()
          Console.WriteLine(info)
       End Sub
    
       Private Function GetCurrentTemperature() As String
          Dim dat As Date = Date.Now
          Dim temp As Decimal = 20.6d
          Dim scale As TemperatureScale = TemperatureScale.Celsius
          Dim result As String 
          
          result = String.Format("At {0:t} on {0:D}, the temperature is {1:F1} {2:G}",
                                 dat, temp, scale)    
          Return result
       End Function
    End Module
    ' The example displays output like the following:
    '       At 10:40 AM on Wednesday, June 04, 2014, the temperature is 20.6 Celsius
    
  • 复合格式字符串的格式不正确。The composite format string isn't well-formed. 发生这种情况时FormatException , 异常始终是由开发人员错误引起的。When this happens, the FormatException exception is always a result of developer error. 应更正此情况, 而不是在try/catch块中进行处理。It should be corrected rather than handled in a try/catch block.

    如以下示例中所示, 尝试在字符串中包含文本大括号会引发异常。Trying to include literal braces in a string, as the following example does, will throw the exception.

    result = String.Format("The text has {0} '{' characters and {1} '}' characters.",
                           nOpen, nClose);
    
    result = String.Format("The text has {0} '{' characters and {1} '}' characters.",
                           nOpen, nClose)
    

    在复合格式字符串中包含大括号的建议方法是将它们包含在对象列表中, 并使用格式项将它们插入到结果字符串中。The recommended technique for including literal braces in a composite format string is to include them in the object list and use format items to insert them into the result string. 例如, 您可以修改上一复合格式字符串, 如下所示。For example, you can modify the previous composite format string as shown here.

    string result;
    int nOpen = 1;
    int nClose = 2;
    result = String.Format("The text has {0} '{{' characters and {1} '}}' characters.",
                           nOpen, nClose);
    Console.WriteLine(result);
    
    result = String.Format("The text has {0} '{{' characters and {1} '}}' characters.",
                           nOpen, nClose)
    

    如果格式字符串包含打字错误, 也会引发异常。The exception is also thrown if your format string contains a typo. 以下对String.Format方法的调用省略了右大括号, 并对左大括号和右括号配对。The following call to the String.Format method omits a closing brace and pairs an opening brace with a closing bracket.

    int n1 = 10;
    int n2 = 20;
    String result = String.Format("{0 + {1] = {2}", 
                                  n1, n2, n1 + n2);
    
    Dim n1 As Integer = 10
    Dim n2 As Integer = 20
    Dim result As String = String.Format("{0 + {1] = {2}", 
                                         n1, n2, n1 + n2)
    

    若要更正此错误, 请确保所有左大括号和右大括号对应。To correct the error, ensure that all opening and closing braces correspond.

    String result = String.Format("{0} + {1} = {2}", 
                                  n1, n2, n1 + n2);
    
    Dim result As String = String.Format("{0} + {1} = {2}", 
                                         n1, n2, n1 + n2)
    
  • 已提供复合格式设置方法中的对象列表作为强类型参数数组, 但该FormatException异常表示一个或多个格式项的索引超过对象列表中的参数数量。You've supplied the object list in a composite formatting method as a strongly typed parameter array, and the FormatException exception indicates that the index of one or more format items exceeds the number of arguments in the object list. 出现这种情况的原因是, 数组类型之间没有显式转换, 因此编译器会将该数组视为单个参数, 而不是作为参数数组。This occurs because no explicit conversion between array types exists, so instead the compiler treats the array as a single argument rather than as a parameter array. 例如, 以下对Console.WriteLine(String, Object[])方法的调用将FormatException引发异常, 尽管格式项的最高索引为 3, 而类型Int32的参数数组具有四个元素。For example, the following call to the Console.WriteLine(String, Object[]) method throws a FormatException exception, although the highest index of the format items is 3, and the parameter array of type Int32 has four elements.

    using System;
    using System.Collections.Generic;
    
    public class Example
    {
       public static void Main()
       {
          Random rnd = new Random();
          int[]  numbers = new int[4];
          int total = 0;
          for (int ctr = 0; ctr <= 2; ctr++) {
             int number = rnd.Next(1001);
             numbers[ctr] = number;
             total += number;
          }   
          numbers[3] = total;
          Console.WriteLine("{0} + {1} + {2} = {3}", numbers);   
       }
    }
    // The example displays the following output:
    //    Unhandled Exception: 
    //    System.FormatException: 
    //       Index (zero based) must be greater than or equal to zero and less than the size of the argument list.
    //       at System.Text.StringBuilder.AppendFormat(IFormatProvider provider, String format, Object[] args)
    //       at System.IO.TextWriter.WriteLine(String format, Object arg0)
    //       at System.IO.TextWriter.SyncTextWriter.WriteLine(String format, Object arg0)
    //       at Example.Main()
    
    Imports System.Collections.Generic
    
    Module Example
       Public Sub Main()
          Dim rnd As New Random()
          Dim numbers(3) As Integer
          Dim total As Integer = 0
          For ctr = 0 To 2
             Dim number As Integer = rnd.Next(1001)
             numbers(ctr) = number
             total += number
          Next
          numbers(3) = total
          Console.WriteLine("{0} + {1} + {2} = {3}", numbers)   
       End Sub
    End Module
    ' The example displays the following output:
    '    Unhandled Exception: 
    '    System.FormatException: 
    '       Index (zero based) must be greater than or equal to zero and less than the size of the argument list.
    '       at System.Text.StringBuilder.AppendFormat(IFormatProvider provider, String format, Object[] args)
    '       at System.IO.TextWriter.WriteLine(String format, Object arg0)
    '       at System.IO.TextWriter.SyncTextWriter.WriteLine(String format, Object arg0)
    '       at Example.Main()
    

    应该消除其原因, 而不是处理此异常。Instead of handling this exception, you should eliminate its cause. 因为既不 Visual Basic C#也不能将整数数组转换为对象数组, 所以必须在调用复合格式设置方法之前自行执行转换。Because neither Visual Basic nor C# can convert an integer array to an object array, you have to perform the conversion yourself before calling the composite formatting method. 下面的示例提供了一个实现。The following example provides one implementation.

    using System;
    using System.Collections.Generic;
    
    public class Example
    {
       public static void Main()
       {
          Random rnd = new Random();
          int[]  numbers = new int[4];
          int total = 0;
          for (int ctr = 0; ctr <= 2; ctr++) {
             int number = rnd.Next(1001);
             numbers[ctr] = number;
             total += number;
          }   
          numbers[3] = total;
          object[] values = new object[numbers.Length];
          numbers.CopyTo(values, 0);
          Console.WriteLine("{0} + {1} + {2} = {3}", values);   
       }
    }
    // The example displays output like the following:
    //        477 + 956 + 901 = 2334
    
    Imports System.Collections.Generic
    
    Module Example
       Public Sub Main()
          Dim rnd As New Random()
          Dim numbers(3) As Integer
          Dim total As Integer = 0
          For ctr = 0 To 2
             Dim number As Integer = rnd.Next(1001)
             numbers(ctr) = number
             total += number
          Next
          numbers(3) = total
          Dim values(numbers.Length - 1) As Object
          numbers.CopyTo(values, 0) 
          Console.WriteLine("{0} + {1} + {2} = {3}", values)   
       End Sub
    End Module
    ' The example displays output like the following:
    '       477 + 956 + 901 = 2334
    

FormatException使用 COR_E_FORMAT 值为0x80131537 的 HRESULT。FormatException uses the HRESULT COR_E_FORMAT, which has the value 0x80131537.

类派生自Exception , 并且不添加唯一成员。 FormatExceptionThe FormatException class derives from Exception and adds no unique members. 有关实例的初始属性值的列表FormatException,请参阅FormatException构造函数。For a list of initial property values for an instance of FormatException, see the FormatException constructors.

构造函数

FormatException() FormatException() FormatException() FormatException()

初始化 FormatException 类的新实例。Initializes a new instance of the FormatException class.

FormatException(SerializationInfo, StreamingContext) FormatException(SerializationInfo, StreamingContext) FormatException(SerializationInfo, StreamingContext) FormatException(SerializationInfo, StreamingContext)

用序列化数据初始化 FormatException 类的新实例。Initializes a new instance of the FormatException class with serialized data.

FormatException(String) FormatException(String) FormatException(String) FormatException(String)

用指定的错误消息初始化 FormatException 类的新实例。Initializes a new instance of the FormatException class with a specified error message.

FormatException(String, Exception) FormatException(String, Exception) FormatException(String, Exception) FormatException(String, Exception)

使用指定的错误消息和对作为此异常原因的内部异常的引用来初始化 FormatException 类的新实例。Initializes a new instance of the FormatException class with a specified error message and a reference to the inner exception that is the cause of this exception.

属性

Data Data Data Data

获取提供有关异常的其他用户定义信息的键/值对集合。Gets a collection of key/value pairs that provide additional user-defined information about the exception.

(Inherited from Exception)
HelpLink HelpLink HelpLink HelpLink

获取或设置指向与此异常关联的帮助文件链接。Gets or sets a link to the help file associated with this exception.

(Inherited from Exception)
HResult HResult HResult HResult

获取或设置 HRESULT(一个分配给特定异常的编码数字值)。Gets or sets HRESULT, a coded numerical value that is assigned to a specific exception.

(Inherited from Exception)
InnerException InnerException InnerException InnerException

获取导致当前异常的 Exception 实例。Gets the Exception instance that caused the current exception.

(Inherited from Exception)
Message Message Message Message

获取描述当前异常的消息。Gets a message that describes the current exception.

(Inherited from Exception)
Source Source Source Source

获取或设置导致错误的应用程序或对象的名称。Gets or sets the name of the application or the object that causes the error.

(Inherited from Exception)
StackTrace StackTrace StackTrace StackTrace

获取调用堆栈上的即时框架字符串表示形式。Gets a string representation of the immediate frames on the call stack.

(Inherited from Exception)
TargetSite TargetSite TargetSite TargetSite

获取引发当前异常的方法。Gets the method that throws the current exception.

(Inherited from Exception)

方法

Equals(Object) Equals(Object) Equals(Object) Equals(Object)

确定指定的对象是否等于当前对象。Determines whether the specified object is equal to the current object.

(Inherited from Object)
GetBaseException() GetBaseException() GetBaseException() GetBaseException()

当在派生类中重写时,返回 Exception,它是一个或多个并发的异常的根源。When overridden in a derived class, returns the Exception that is the root cause of one or more subsequent exceptions.

(Inherited from Exception)
GetHashCode() GetHashCode() GetHashCode() GetHashCode()

作为默认哈希函数。Serves as the default hash function.

(Inherited from Object)
GetObjectData(SerializationInfo, StreamingContext) GetObjectData(SerializationInfo, StreamingContext) GetObjectData(SerializationInfo, StreamingContext) GetObjectData(SerializationInfo, StreamingContext)

当在派生类中重写时,用关于异常的信息设置 SerializationInfoWhen overridden in a derived class, sets the SerializationInfo with information about the exception.

(Inherited from Exception)
GetType() GetType() GetType() GetType()

获取当前实例的运行时类型。Gets the runtime type of the current instance.

(Inherited from Exception)
MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

创建当前 Object 的浅表副本。Creates a shallow copy of the current Object.

(Inherited from Object)
ToString() ToString() ToString() ToString()

创建并返回当前异常的字符串表示形式。Creates and returns a string representation of the current exception.

(Inherited from Exception)

事件

SerializeObjectState SerializeObjectState SerializeObjectState SerializeObjectState

当异常被序列化用来创建包含有关该异常的徐列出数据的异常状态对象时会出现该问题。Occurs when an exception is serialized to create an exception state object that contains serialized data about the exception.

(Inherited from Exception)

适用于

另请参阅