Export (0) Print
Expand All

Trace.Fail Method (String)

Emits the specified error message.

Namespace: System.Diagnostics
Assembly: System (in system.dll)

[ConditionalAttribute("TRACE")] 
public static void Fail (
	string message
)
/** @attribute ConditionalAttribute("TRACE") */ 
public static void Fail (
	String message
)
ConditionalAttribute("TRACE") 
public static function Fail (
	message : String
)

Parameters

message

A message to emit.

The default behavior for the default trace listener is to output the message parameter to a message box when the application runs in user-interface mode, and to the TraceListener instances in the Listeners collection. You can customize this behavior by adding a TraceListener to, or by removing one from, the Listeners collection.

The following example uses the Fail method to print a message during exception handling.

catch (Exception) {
    Trace.Fail("Cannot find SpecialController, proceeding with StandardController");
}

catch (System.Exception exp) {
    Trace.Fail("Cannot find SpecialController," 
        + "proceeding with StandardController");
}

try{
    // try something here
}catch(e : Exception){
    Trace.Fail("Operation failed.")
}


You can also use the Fail method in a switch statement.

switch (option) {
    case Option.First:
       result = 1.0;
       break;
 
    // Insert additional cases.
    default:
       Trace.Fail("Unknown Option " + option);
       result = 1.0;
       break;
}

switch (option) {
    case Option.first :
        result = 1.0;
        break;
    // Insert additional cases.
    default :
        Trace.Fail(("Unknown Option " + option));
        result = 1.0;
        break;
}

switch(value){
  case 1:
    result = 2.0
    break
  case 2:
    result = 4.0
    break

  // Insert additional cases.

  default:
    Trace.Fail("Unexpected value: " + value)
    result = 0.0
}


Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

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

.NET Framework

Supported in: 2.0, 1.1, 1.0

Community Additions

ADD
Show:
© 2015 Microsoft