<legacyCorruptedStateExceptionsPolicy > 元素<legacyCorruptedStateExceptionsPolicy> Element

指定通用語言執行時間是否允許 managed 程式碼攔截存取違規和其他損毀狀態例外狀況。Specifies whether the common language runtime allows managed code to catch access violations and other corrupted state exceptions.

<configuration> <configuration>
    <runtime >   <runtime>
     <legacyCorruptedStateExceptionsPolicy >    <legacyCorruptedStateExceptionsPolicy>

語法Syntax

<legacyCorruptedStateExceptionsPolicy enabled="true|false"/>  

屬性和項目Attributes and Elements

下列各節描述屬性、子項目和父項目。The following sections describe attributes, child elements, and parent elements.

屬性Attributes

屬性Attribute 描述Description
enabled 必要屬性。Required attribute.

指定應用程式將會攔截損毀狀態例外狀況失敗,例如存取違規。Specifies that the application will catch corrupting state exception failures such as access violations.

啟用屬性enabled Attribute

Value 描述Description
false 應用程式將不會攔截損毀狀態例外狀況失敗,例如存取違規。The application will not catch corrupting state exception failures such as access violations. 這是預設值。This is the default.
true 應用程式將會攔截損毀狀態例外狀況失敗,例如存取違規。The application will catch corrupting state exception failures such as access violations.

子項目Child Elements

無。None.

父項目Parent Elements

項目Element 描述Description
configuration 通用語言執行平台和 .NET Framework 應用程式所使用之每個組態檔中的根項目。The root element in every configuration file used by the common language runtime and .NET Framework applications.
runtime 包含有關組件繫結和記憶體回收的資訊。Contains information about assembly binding and garbage collection.

備註Remarks

在 .NET Framework 版本3.5 和舊版中,通用語言執行平臺允許 managed 程式碼攔截因進程狀態損毀而引發的例外狀況。In the .NET Framework version 3.5 and earlier, the common language runtime allowed managed code to catch exceptions that were raised by corrupted process states. 存取違規是這類例外狀況的範例。An access violation is an example of this type of exception.

從 .NET Framework 4 開始,managed 程式碼就不會再于 catch 組塊中捕捉這些類型的例外狀況。Starting with the .NET Framework 4, managed code no longer catches these types of exceptions in catch blocks. 不過,您可以透過兩種方式來覆寫此變更並維護損毀狀態例外狀況的處理:However, you can override this change and maintain the handling of corrupted state exceptions in two ways:

  • <legacyCorruptedStateExceptionsPolicy> 元素的 enabled 屬性設定為 [true]。Set the <legacyCorruptedStateExceptionsPolicy> element's enabled attribute to true. 此設定會套用 processwide,並會影響所有方法。This configuration setting is applied processwide and affects all methods.

-或--or-

此 configuration 元素僅適用于 .NET Framework 4 和更新版本。This configuration element is available only in the .NET Framework 4 and later.

範例Example

下列範例顯示如何指定應用程式應該還原為 .NET Framework 4 之前的行為,並攔截所有損毀狀態例外狀況失敗。The following example shows how to specify that the application should revert to the behavior before the .NET Framework 4, and catch all corrupting state exception failures.

<configuration>  
   <runtime>  
      <legacyCorruptedStateExceptionsPolicy enabled="true" />  
   </runtime>  
</configuration>  

請參閱See also