FileNotFoundException.cs 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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. //
  11. // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
  12. //
  13. // Permission is hereby granted, free of charge, to any person obtaining
  14. // a copy of this software and associated documentation files (the
  15. // "Software"), to deal in the Software without restriction, including
  16. // without limitation the rights to use, copy, modify, merge, publish,
  17. // distribute, sublicense, and/or sell copies of the Software, and to
  18. // permit persons to whom the Software is furnished to do so, subject to
  19. // the following conditions:
  20. //
  21. // The above copyright notice and this permission notice shall be
  22. // included in all copies or substantial portions of the Software.
  23. //
  24. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  25. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  26. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  27. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  28. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  29. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  30. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  31. //
  32. using System.Globalization;
  33. using System.IO;
  34. using System.Runtime.Serialization;
  35. namespace System.IO {
  36. [Serializable]
  37. public class FileNotFoundException : IOException {
  38. private string fileName;
  39. private string fusionLog;
  40. // Constructors
  41. public FileNotFoundException ()
  42. : base (Locale.GetText ("File not found"))
  43. {
  44. }
  45. public FileNotFoundException (string message)
  46. : base (message)
  47. {
  48. }
  49. public FileNotFoundException (string message, Exception inner)
  50. : base (message, inner)
  51. {
  52. }
  53. public FileNotFoundException (string message, string fileName)
  54. : base (message)
  55. {
  56. this.fileName = fileName;
  57. }
  58. public FileNotFoundException (string message, string fileName, Exception innerException)
  59. : base (message, innerException)
  60. {
  61. this.fileName = fileName;
  62. }
  63. protected FileNotFoundException (SerializationInfo info, StreamingContext context)
  64. : base (info, context)
  65. {
  66. fileName = info.GetString ("FileNotFound_FileName");
  67. fusionLog = info.GetString ("FileNotFound_FusionLog");
  68. }
  69. public string FileName
  70. {
  71. get { return fileName; }
  72. }
  73. public string FusionLog
  74. {
  75. get { return fusionLog; }
  76. }
  77. public override string Message
  78. {
  79. get {
  80. if (base.Message == null)
  81. return "File not found";
  82. if (fileName == null)
  83. return base.Message;
  84. return "File '" + fileName + "' not found.";
  85. }
  86. }
  87. public override void GetObjectData (SerializationInfo info, StreamingContext context)
  88. {
  89. base.GetObjectData (info, context);
  90. info.AddValue ("FileNotFound_FileName", fileName);
  91. info.AddValue ("FileNotFound_FusionLog", fusionLog);
  92. }
  93. public override string ToString ()
  94. {
  95. string result = GetType ().FullName + ": " + Message;
  96. if (InnerException != null)
  97. result += " ----> " + InnerException.ToString ();
  98. if (StackTrace != null)
  99. result += "\n" + StackTrace;
  100. return result;
  101. }
  102. }
  103. }