Environment.FailFast 方法

定義

在回報錯誤訊息前立即終止程序。 對於 Windows,錯誤訊息會寫入 Windows 應用程式事件日誌,訊息及可選的例外資訊會包含在向 Microsoft 回報錯誤時。 對於類 Unix 系統,訊息與堆疊追蹤一同寫入標準錯誤流。

多載

名稱 Description
FailFast(String)

在回報錯誤訊息前立即終止程序。 對於 Windows,錯誤訊息會寫入 Windows 應用程式事件日誌,並包含在錯誤回報中給 Microsoft。 對於類 Unix 系統,訊息與堆疊追蹤一同寫入標準錯誤流。

FailFast(String, Exception)

在回報錯誤訊息前立即終止程序。 對於 Windows,錯誤訊息會寫入 Windows 應用程式事件日誌,訊息與例外資訊則包含在向 Microsoft 回報錯誤時。 對於類 Unix 系統,與堆疊追蹤一同的訊息會寫入標準錯誤串流。

FailFast(String)

來源:
Environment.CoreCLR.cs
來源:
Environment.CoreCLR.cs
來源:
Environment.cs
來源:
Environment.cs
來源:
Environment.CoreCLR.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.FailFast 方法會將 message 字串寫入 Windows 應用程式事件日誌,建立應用程式的傾印,然後終止目前的程序。 message字串也包含在錯誤報告中,透過Windows錯誤報告向Microsoft報告。 更多資訊請參見 Windows錯誤回報:入門

在類 Unix 系統中,訊息會寫入標準錯誤流,與堆疊追蹤資訊一同記錄。

如果應用程式狀態損壞到無法修復,且執行應用程式Environment.FailFastExittry的區塊和終結器會破壞程式資源,請使用/方法而非finally終止方法。

呼叫 Environment.FailFast 方法來終止在 Visual Studio 除錯器中執行的應用程式,會拋出 ExecutionEngineException,並自動觸發 fatalExecutionEngineError 管理除錯助理(MDA)

適用於

FailFast(String, Exception)

來源:
Environment.CoreCLR.cs
來源:
Environment.CoreCLR.cs
來源:
Environment.cs
來源:
Environment.cs
來源:
Environment.CoreCLR.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.FailFast 方法會將 message 字串寫入 Windows 應用程式事件日誌,建立應用程式的傾印,然後終止目前的程序。

資訊會透過 Windows 錯誤報告系統向 Microsoft 報告。 更多資訊請參見 Windows錯誤回報:入門。 錯誤回報Microsoft包含messageexception 資訊,這些資訊提供用於分類錯誤的細節。 雖然 exception 程序已終止,無法處理,但引發例外的上下文資訊仍會被取得。

在類 Unix 系統中,訊息會寫入標準錯誤流,與堆疊追蹤資訊一同記錄。

exception 是 ,或null若 未拋出,此方法的運作方式與exception方法FailFast(String)過載相同。

如果應用程式狀態損壞到無法修復,且執行應用程式Environment.FailFastExittry的區塊和終結器會破壞程式資源,請使用/方法而非finally終止方法。

呼叫 Environment.FailFast 方法來終止在 Visual Studio 除錯器中執行的應用程式,會拋出 ExecutionEngineException,並自動觸發 fatalExecutionEngineError 管理除錯助理(MDA)

適用於