Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

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

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.