Redigera

Dela via


DefaultTraceListener.Fail Method

Definition

Emits or displays a message and a stack trace for an assertion that always fails.

Overloads

Fail(String)

Emits or displays a message and a stack trace for an assertion that always fails.

Fail(String, String)

Emits or displays detailed messages and a stack trace for an assertion that always fails.

Fail(String)

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

Emits or displays a message and a stack trace for an assertion that always fails.

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)

Parameters

message
String

The message to emit or display.

Examples

The following code example writes an error message to a DefaultTraceListener using the Fail(String) method. The method also writes the message to the console if a user interface is not available.

// 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

Remarks

By default, this method sends the message parameter and a stack trace to a message box (when the application runs in user-interface mode) and to the DefaultTraceListener instance.

See also

Applies to

Fail(String, String)

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

Emits or displays detailed messages and a stack trace for an assertion that always fails.

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)

Parameters

message
String

The message to emit or display.

detailMessage
String

The detailed message to emit or display.

Examples

The following code example calls a function that calls the Fail(String, String) method to log a detailed error message if the function throws an exception. The method writes the message to the console if a user interface is not available.

// 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

Remarks

By default, this method sends the message parameter, the detailMessage parameter, and a stack trace to a message box (when the application runs in user-interface mode) and to the DefaultTraceListener instance.

See also

Applies to