FileNotFoundException.cs 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. //
  2. // System.IO.FileNotFoundException.cs
  3. //
  4. // Author:
  5. // Paolo Molaro ([email protected])
  6. // Duncan Mak ([email protected])
  7. //
  8. // (C) 2001 Ximian, Inc. http://www.ximian.com
  9. //
  10. using System.Globalization;
  11. using System.IO;
  12. using System.Runtime.Serialization;
  13. namespace System.IO {
  14. [Serializable]
  15. public class FileNotFoundException : IOException {
  16. private string fileName;
  17. private string fusionLog;
  18. // Constructors
  19. public FileNotFoundException ()
  20. : base (Locale.GetText ("File not found"))
  21. {
  22. }
  23. public FileNotFoundException (string message)
  24. : base (message)
  25. {
  26. }
  27. public FileNotFoundException (string message, Exception inner)
  28. : base (message, inner)
  29. {
  30. }
  31. public FileNotFoundException (string message, string fileName)
  32. : base (message)
  33. {
  34. this.fileName = fileName;
  35. }
  36. public FileNotFoundException (string message, string fileName, Exception innerException)
  37. : base (message, innerException)
  38. {
  39. this.fileName = fileName;
  40. }
  41. protected FileNotFoundException (SerializationInfo info, StreamingContext context)
  42. : base (info, context)
  43. {
  44. fileName = info.GetString ("FileNotFound_FileName");
  45. fusionLog = info.GetString ("FileNotFound_FusionLog");
  46. }
  47. public string FileName
  48. {
  49. get { return fileName; }
  50. }
  51. public string FusionLog
  52. {
  53. get { return fusionLog; }
  54. }
  55. public override string Message
  56. {
  57. get {
  58. if (base.Message == null)
  59. return "File not found";
  60. if (fileName == null)
  61. return base.Message;
  62. return "File '" + fileName + "' not found.";
  63. }
  64. }
  65. public override void GetObjectData (SerializationInfo info, StreamingContext context)
  66. {
  67. info.AddValue ("FileNotFound_FileName", fileName);
  68. info.AddValue ("FileNotFound_FusionLog", fusionLog);
  69. }
  70. public override string ToString ()
  71. {
  72. string result = GetType ().FullName + ": " + Message;
  73. if (InnerException != null)
  74. result += " ----> " + InnerException.ToString ();
  75. if (StackTrace != null)
  76. result += "\n" + StackTrace;
  77. return result;
  78. }
  79. }
  80. }