DefaultTraceListener.Fail Method
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Emits or displays a message and a stack trace for an assertion that always fails.
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. |
- 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
.NET 9 és más verziók
Termék | Verziók |
---|---|
.NET | Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9 |
.NET Framework | 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1 |
.NET Standard | 2.0, 2.1 |
- 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
.NET 9 és más verziók
Termék | Verziók |
---|---|
.NET | Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9 |
.NET Framework | 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1 |
.NET Standard | 2.0, 2.1 |
.NET-visszajelzés
A(z) .NET egy nyílt forráskód projekt. Visszajelzés adásához válasszon egy hivatkozást: