Returns a string representation of the current instance.
A String representation of the current Exception.
The string representation returned by this method includes the fully qualified name of the current Exception, the message, the result of calling ToString on the inner Exception, the file name, and the result of calling Environment.StackTrace. Null values are omitted from the returned string.
Note: This method overrides object.ToString.
The following example causes a System.IO.FileNotFoundException exception and displays the result of calling ToString on that Exception.
C# Example
using System; using System.IO; class FileNotFoundExample { public static void Main () { string badPath = "/Eccma/examples/FileTest.cs"; string goodPath = "/Ecma/examples2/FileTest.cs"; try { File.Copy(badPath,goodPath); } catch (FileNotFoundException e) { Console.WriteLine("Caught: {0}",e.ToString()); } } }The output is
Example
Caught: System.IO.FileNotFoundException: Could not find file "/Eccma/examples/FileTest.cs". File name: "/Eccma/examples/FileTest.cs" at System.IO.__Error.WinIOError(Int32 errorCode, String str) at System.IO.File.InternalCopy(String sourceFileName, String destFileName, Boolean overwrite) at FileNotFoundExample.Main()
Namespace: System.IO
Assembly: mscorlib (in mscorlib.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0