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
继承
派生
属性

注解

一个FormatException出于以下原因之一可能会引发异常:A 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类和ParseParseExact某些类型的方法。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.
    

    一个FormatException也可由分析方法,例如引发异常DateTime.ParseExactGuid.ParseExact,需要要进行分析,以完全符合格式字符串指定的模式的字符串。A 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. 相反,它具有仅三dattemp,并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变量,然后递减 1 每个后续的格式项的索引。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 使用 HRESULT COR_E_FORMAT,其值 0x80131537。FormatException uses the HRESULT COR_E_FORMAT, which has the value 0x80131537.

FormatException类派生自Exception并添加任何独特的成员。The 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)

适用于

另请参阅