Environment.FailFast 方法

定义

在报告错误消息之前立即终止进程。 对于 Windows,错误消息将写入 Windows 应用程序事件日志,并且消息和可选异常信息包含在向 Microsoft 报告的错误中。 对于类似 Unix 的系统,消息与堆栈跟踪一起写入标准错误流。

重载

FailFast(String)

在报告错误消息之前立即终止进程。 对于 Windows,错误消息将写入 Windows 应用程序事件日志,并且该消息包含在向 Microsoft 报告错误中。 对于类似 Unix 的系统,消息与堆栈跟踪一起写入标准错误流。

FailFast(String, Exception)

在报告错误消息之前立即终止进程。 对于 Windows,错误消息将写入 Windows 应用程序事件日志,并且消息和异常信息包含在向 Microsoft 报告的错误中。 对于类似 Unix 的系统,堆栈跟踪旁的消息将写入标准错误流。

FailFast(String)

在报告错误消息之前立即终止进程。 对于 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.FailFast如果应用程序的状态损坏无法修复,并且执行try/finally应用程序的块和终结器会损坏程序资源,请使用 方法而不是 Exit 方法终止应用程序。

Environment.FailFast调用 方法来终止在 Visual Studio 调试器中运行的应用程序的执行会ExecutionEngineException引发 并自动触发 fatalExecutionEngineError 托管调试助手 (MDA)

适用于

FailFast(String, Exception)

在报告错误消息之前立即终止进程。 对于 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 的系统上,消息将连同堆栈跟踪信息一起写入标准错误流。

如果 exceptionnull,或者如果未 exception 引发 ,则此方法的操作与方法重载相同 FailFast(String)

Environment.FailFast如果应用程序的状态损坏无法修复,并且执行try/finally应用程序的块和终结器会损坏程序资源,请使用 方法而不是 Exit 方法终止应用程序。

Environment.FailFast调用 方法来终止在 Visual Studio 调试器中运行的应用程序的执行会ExecutionEngineException引发 并自动触发 fatalExecutionEngineError 托管调试助手 (MDA)

适用于