DefaultTraceListener.Fail 方法

定义

为总是失败的断言发出或显示消息和堆栈跟踪。

重载

Fail(String)

为总是失败的断言发出或显示消息和堆栈跟踪。

Fail(String, String)

为总是失败的断言发出或显示详细消息和堆栈跟踪。

Fail(String)

Source:
DefaultTraceListener.cs
Source:
DefaultTraceListener.cs
Source:
DefaultTraceListener.cs

为总是失败的断言发出或显示消息和堆栈跟踪。

public:
 override void Fail(System::String ^ message);
public override void Fail (string? message);
public override void Fail (string message);
override this.Fail : string -> unit
Public Overrides Sub Fail (message As String)

参数

message
String

要发出或显示的消息。

示例

下面的代码示例使用 Fail(String) 方法将错误消息写入 。DefaultTraceListener 如果用户界面不可用, 方法还会将消息写入控制台。

// Report that the required argument is not present.
const string ENTER_PARAM = "Enter the number of " +
          "possibilities as a command line argument.";
defaultListener.Fail(ENTER_PARAM);
if (!defaultListener.AssertUiEnabled)
{
    Console.WriteLine(ENTER_PARAM);
}
' Report that the required argument is not present.
Const ENTER_PARAM As String = "Enter the number of " & _
    "possibilities as a command line argument."
defaultListener.Fail(ENTER_PARAM)
If Not defaultListener.AssertUiEnabled Then
    Console.WriteLine(ENTER_PARAM)
End If

注解

默认情况下,此方法将 message 参数和堆栈跟踪发送到消息框, (应用程序在用户界面模式下运行时) 和 DefaultTraceListener 实例。

另请参阅

适用于

Fail(String, String)

Source:
DefaultTraceListener.cs
Source:
DefaultTraceListener.cs
Source:
DefaultTraceListener.cs

为总是失败的断言发出或显示详细消息和堆栈跟踪。

public:
 override void Fail(System::String ^ message, System::String ^ detailMessage);
public override void Fail (string? message, string? detailMessage);
public override void Fail (string message, string detailMessage);
override this.Fail : string * string -> unit
Public Overrides Sub Fail (message As String, detailMessage As String)

参数

message
String

要发出或显示的消息。

detailMessage
String

要发出或显示的详细消息。

示例

下面的代码示例调用一个函数,该函数调用 Fail(String, String) 方法以在函数引发异常时记录详细的错误消息。 如果用户界面不可用, 方法会将消息写入控制台。

// Compute the next binomial coefficient and handle all exceptions.
try
{
    result = CalcBinomial(possibilities, iter);
}
catch(Exception ex)
{
    string failMessage = String.Format("An exception was raised when " +
        "calculating Binomial( {0}, {1} ).", possibilities, iter);
    defaultListener.Fail(failMessage, ex.Message);
    if (!defaultListener.AssertUiEnabled)
    {
        Console.WriteLine(failMessage+ "\n" +ex.Message);
    }
    return;
}
' Compute the next binomial coefficient and handle all exceptions.
Try
    result = CalcBinomial(possibilities, iter)
Catch ex As Exception
    Dim failMessage As String = String.Format( _
            "An exception was raised when " & _
            "calculating Binomial( {0}, {1} ).", _
            possibilities, iter)
    defaultListener.Fail(failmessage, ex.Message)
    If Not defaultListener.AssertUiEnabled Then
        Console.WriteLine(failMessage & vbCrLf & ex.Message)
    End If
    Return
End Try

注解

默认情况下,此方法将 message 参数、 detailMessage 参数和堆栈跟踪发送到消息框, (应用程序在用户界面模式下运行时) 和 DefaultTraceListener 实例。

另请参阅

适用于