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
繼承
衍生
屬性

備註

AFormatException可以擲回例外狀況的其中一個原因如下: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:

    • Boolean.Boolean. 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.
    

    AFormatException例外狀況也會藉由剖析方法,例如擲回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變數,並遞減一個每個後續的格式項目的索引。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()

在衍生類別中覆寫時,傳回一或多個後續的例外狀況的根本原因 ExceptionWhen 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 的淺層複本 (Shallow Copy)。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)

適用於

另請參閱