Presentation is loading. Please wait.

Presentation is loading. Please wait.

Error Handling – the Debug and Trace Classes

Similar presentations


Presentation on theme: "Error Handling – the Debug and Trace Classes"— Presentation transcript:

1 Error Handling – the Debug and Trace Classes
Debug and Trace classes allow you to produce and log informative messages about your application’s conditions without having to interrupt application execution. Trace and Debug are in System.Diagnostics Output is sent to: Output window in Visual Studio and to the Listeners collection. Trace = Debug, only difference is only Trace statements make it into release builds. So, Trace and Debug send output to Listeners collection, then flags you set in Listeners collection determines where output is ultimately is sent (text file, event log, etc…)

2 Error Handling – the Debug and Trace Classes
Debug/Trace have six methods for writing output to Listeners: Output only… Write – Trace.Write(“Trace Message 1”); WriteLine – Trace.WriteLine(“Trace Message 2”); WriteIf – Debug.WriteIf(X==Y, “X equals Y”); WriteLineIf – Debug.WriteLineIf(X==Y, “X equals Y”); Output and MessageBox, if false…. Assert – Trace.Assert(X==Y, “X does not equal Y!”); Output and MessageBox… Fail – Debug.Fail(“Drive B is no longer valid.”); Can format the output using Trace.Indent or .Unindent

3 Listeners Collection Receives output from Trace and Debug, how that output is handled is up to the individual listener. Can log to: Console window Text file Event Log MessageBox Output can be dynamically set at design OR runtime using TraceSwiches which are set in application configuration (XML) file. Extension is “.config”.


Download ppt "Error Handling – the Debug and Trace Classes"

Similar presentations


Ads by Google