Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

Trace.Fail Method

Emits an error message.

Overload List

Emits the specified error message.

[Visual Basic] Overloads Public Shared Sub Fail(String)
[C#] public static void Fail(string);
[C++] public: static void Fail(String*);
[JScript] public static function Fail(String);

Emits an error message, and a detailed error message.

[Visual Basic] Overloads Public Shared Sub Fail(String, String)
[C#] public static void Fail(string, string);
[C++] public: static void Fail(String*, String*);
[JScript] public static function Fail(String, String);

Example

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

[Visual Basic] 
Catch
    Trace.Fail("Invalid value: " & value.ToString(), _
        "Resetting value to newValue.")
    value = newValue
End Try

[C#] 
catch (Exception) {
    Trace.Fail("Invalid value: " + value.ToString(), 
       "Resetting value to newValue.");
    value = newValue;
}

[C++] 
catch (Exception*) {
    Trace::Fail(String::Format( S"Invalid value: {0}", __box(value)), 
       S"Resetting value to newValue.");
    value = newValue;
}

[JScript] 
}catch(e : Exception){
    Trace.Fail("Invalid value: " + value.ToString(), "Resetting value to newValue.")
    value = newValue
}

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

[Visual Basic] 
Select Case option1
    Case OptionConsts.First
        result = 1.0
    
    ' Insert additional cases.
    Case Else
        Trace.Fail("Unsupported option " & option1, "Result set to 1.0")
        result = 1.0
End Select

[C#] 
switch (option) {
    case Option.First:
       result = 1.0;
       break;
 
    // Insert additional cases.
 
    default:
       Trace.Fail("Unsupported option " + option, "Result set to 1.0");
       result = 1.0;
       break;
}

[C++] 
switch (option) {
    case Option::First:
       result = 1.0;
       break;
 
    // Insert additional cases.
 
    default:
       Trace::Fail(String::Format( S"Unsupported option {0}", __box(option)), S"Result set to 1.0");
       result = 1.0;
       break;
}

[JScript] 
switch(option){
  case 1:
    result = 1.0
    break
  // Insert additional cases.
  default:
    Trace.Fail("Unknown option: " + option, "result set to 1.0")
    result = 1.0
}

See Also

Trace Class | Trace Members | System.Diagnostics Namespace

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft