Environment.FailFast 方法

定義

在報告錯誤訊息之前,立即終止進程。 針對 Windows,錯誤訊息會寫入 Windows 應用程式事件記錄檔,而訊息和選擇性例外狀況資訊會包含在向 Microsoft 回報的錯誤中。 針對類似 Unix 的系統,訊息會連同堆疊追蹤一起寫入標準錯誤資料流程。

多載

FailFast(String)

在報告錯誤訊息之前,立即終止進程。 針對 Windows,錯誤訊息會寫入 Windows 應用程式事件記錄檔,而且訊息會包含在向 Microsoft 回報的錯誤中。 針對類似 Unix 的系統,訊息會連同堆疊追蹤一起寫入標準錯誤資料流程。

FailFast(String, Exception)

在報告錯誤訊息之前,立即終止進程。 針對 Windows,錯誤訊息會寫入 Windows 應用程式事件記錄檔,並將訊息和例外狀況資訊包含在向 Microsoft 回報的錯誤中。 針對類似 Unix 的系統,堆疊追蹤旁的訊息會寫入標準錯誤資料流程。

FailFast(String)

Source:
Environment.cs
Source:
Environment.cs
Source:
Environment.cs

在報告錯誤訊息之前,立即終止進程。 針對 Windows,錯誤訊息會寫入 Windows 應用程式事件記錄檔,而且訊息會包含在向 Microsoft 回報的錯誤中。 針對類似 Unix 的系統,訊息會連同堆疊追蹤一起寫入標準錯誤資料流程。

public:
 static void FailFast(System::String ^ message);
[System.Security.SecurityCritical]
public static void FailFast (string message);
public static void FailFast (string? message);
public static void FailFast (string message);
[<System.Security.SecurityCritical>]
static member FailFast : string -> unit
static member FailFast : string -> unit
Public Shared Sub FailFast (message As String)

參數

message
String

解釋處理程序結束原因的訊息;如果未提供任何解釋,則為 null

屬性

範例

下列範例會在 Windows 下執行時,將記錄專案寫入 Windows 應用程式事件記錄檔,或在類似 Unix 的系統下執行時,將錯誤訊息寫入標準錯誤資料流程,並終止目前的進程。

using System;

class Example
{
    public static void Main()
    {
       string causeOfFailure = "A catastrophic failure has occurred.";

       // Assume your application has failed catastrophically and must
       // terminate immediately. The try-finally block is not executed
       // and is included only to demonstrate that instructions within
       // try-catch blocks and finalizers are not performed.
       try
       {
           Environment.FailFast(causeOfFailure);
       }
       finally
       {
           Console.WriteLine("This finally block will not be executed.");
       }
   }
}
/*
The example produces no output because the application is terminated.
However, an entry is made in the Windows Application event log, and
the log entry contains the text from the causeOfFailure variable.
*/
open System

let causeOfFailure = "A catastrophic failure has occurred."

// Assume your application has failed catastrophically and must
// terminate immediately. The try-finally block is not executed
// and is included only to demonstrate that instructions within
// try-catch blocks and finalizers are not performed.
try
    Environment.FailFast causeOfFailure
finally
    printfn "This finally block will not be executed."

// The example produces no output because the application is terminated.
// However, an entry is made in the Windows Application event log, and
// the log entry contains the text from the causeOfFailure variable.
Module Example
    Public Sub Main()
        Dim causeOfFailure As String = "A catastrophic failure has occurred."
        ' Assume your application has failed catastrophically and must
        ' terminate immediately. The try-finally block is not executed 
        ' and is included only to demonstrate that instructions within 
        ' try-catch blocks and finalizers are not performed.

        Try
            Environment.FailFast(causeOfFailure)
        Finally
            Console.WriteLine("This finally block will not be executed.")
        End Try
    End Sub
End Module
'
' The code example displays no output because the application is
' terminated. However, an entry is made in the Windows Application event
' log, and the log entry contains the text from the causeOfFailure variable.

備註

這個方法會終止進程,而不執行任何作用中的 try/finally 區塊或完成項。

在 Windows 上,方法會將 Environment.FailFastmessage 字串寫入 Windows 應用程式事件記錄檔、建立應用程式的傾印,然後終止目前的進程。 此 message 字串也會包含在透過Windows 錯誤報告向 Microsoft 回報的錯誤中。 如需詳細資訊,請參閱Windows 錯誤報告:消費者入門

在類似 Unix 的系統上,訊息會連同堆疊追蹤資訊一起寫入標準錯誤資料流程。

Environment.FailFast如果應用程式的狀態已損毀超過修復,而且執行應用程式的區塊和完成項將會損毀程式資源,請使用 方法,而不是 Exit 方法來終止您的應用程式 /tryfinally

Environment.FailFast呼叫 方法來終止在 Visual Studio 偵錯工具中執行的應用程式執行會 ExecutionEngineException 擲回 ,並自動觸發嚴重ExecutionEngineError Managed 偵錯助理 (MDA)

適用於

FailFast(String, Exception)

Source:
Environment.cs
Source:
Environment.cs
Source:
Environment.cs

在報告錯誤訊息之前,立即終止進程。 針對 Windows,錯誤訊息會寫入 Windows 應用程式事件記錄檔,並將訊息和例外狀況資訊包含在向 Microsoft 回報的錯誤中。 針對類似 Unix 的系統,堆疊追蹤旁的訊息會寫入標準錯誤資料流程。

public:
 static void FailFast(System::String ^ message, Exception ^ exception);
[System.Security.SecurityCritical]
public static void FailFast (string message, Exception exception);
public static void FailFast (string? message, Exception? exception);
public static void FailFast (string message, Exception exception);
[<System.Security.SecurityCritical>]
static member FailFast : string * Exception -> unit
static member FailFast : string * Exception -> unit
Public Shared Sub FailFast (message As String, exception As Exception)

參數

message
String

解釋處理程序結束原因的訊息;如果未提供任何解釋,則為 null

exception
Exception

表示造成終止之錯誤的例外狀況。 這通常是 catch 區塊中的例外狀況。

屬性

備註

這個方法會終止進程,而不執行任何使用中的 try/finally 區塊或完成項。

在 Windows 上,方法會將 Environment.FailFastmessage 字串寫入 Windows 應用程式事件記錄檔、建立應用程式的傾印,然後終止目前的進程。

使用Windows 錯誤報告向 Microsoft 回報資訊。 如需詳細資訊,請參閱Windows 錯誤報告:消費者入門。 向 Microsoft 回報錯誤包含 messageexception 資訊,其提供用來分類錯誤的詳細資料。 雖然 exception 因為進程終止而未處理,但仍會取得引發例外狀況的內容資訊。

在類似 Unix 的系統上,訊息會連同堆疊追蹤資訊一起寫入標準錯誤資料流程。

如果 為 exception ,如果 exception 不是 null 擲回 ,則這個方法的運作方式與 FailFast(String) 方法多載相同。

Environment.FailFast如果應用程式的狀態已損毀超過修復,而且執行應用程式的區塊和完成項將會損毀程式資源,請使用 方法,而不是 Exit 方法來終止您的應用程式 /tryfinally

Environment.FailFast呼叫 方法來終止在 Visual Studio 偵錯工具中執行的應用程式執行會 ExecutionEngineException 擲回 ,並自動觸發嚴重ExecutionEngineError Managed 偵錯助理 (MDA)

適用於