Click to Rate and Give Feedback
MSDN
MSDN Library
.NET Development
.NET Framework 3.5
Fail Method
 Fail Method (String)
Collapse All/Expand All Collapse All
This page is specific to
Microsoft Visual Studio 2008/.NET Framework 3.5

Other versions are also available for the following:
.NET Framework Class Library
DefaultTraceListener..::.Fail Method (String)

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

Namespace:  System.Diagnostics
Assembly:  System (in System.dll)
Visual Basic (Declaration)
Public Overrides Sub Fail ( _
    message As String _
)
Visual Basic (Usage)
Dim instance As DefaultTraceListener
Dim message As String

instance.Fail(message)
C#
public override void Fail(
    string message
)
Visual C++
public:
virtual void Fail(
    String^ message
) override
JScript
public override function Fail(
    message : String
)

Parameters

message
Type: System..::.String
The message to emit or display.

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.

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.

Visual Basic
' 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
C#
// 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);
}

Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98, Windows CE, Windows Mobile for Smartphone, Windows Mobile for Pocket PC, Xbox 360, Zune

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0, 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 3.5

XNA Framework

Supported in: 3.0, 2.0, 1.0
Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Processing
© 2009 Microsoft Corporation. All rights reserved. Terms of Use | Trademarks | Privacy Statement | Site Feedback
Page view tracker