Returns the fully qualified name of this exception and possibly the error message, the name of the inner exception, and the stack trace.
The fully qualified name of this exception and possibly the error message, the name of the inner exception, and the stack trace.
This method overrides object.ToString.
The string representation returned by this method includes the name of the exception, the value of the FileNotFoundException.Message property, the result of calling ToString on the inner exception, the value of the FileNotFoundException.FileName property, and the result of calling Environment.StackTrace. If any of these members is a null reference, its value is not included in the returned string.
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()