Exception.cs 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. //
  2. // System.Exception.cs
  3. //
  4. // Author:
  5. // Miguel de Icaza ([email protected])
  6. //
  7. // (C) Ximian, Inc. http://www.ximian.com
  8. //
  9. using System.Runtime.Serialization;
  10. using System.Reflection;
  11. namespace System {
  12. public class Exception : ISerializable {
  13. Exception inner_exception;
  14. string message;
  15. string help_link;
  16. string stack_trace = "TODO: implement stack traces";
  17. int hresult;
  18. private string source;
  19. public Exception ()
  20. {
  21. inner_exception = null;
  22. message = "";
  23. }
  24. public Exception (string msg)
  25. {
  26. inner_exception = null;
  27. message = msg;
  28. }
  29. protected Exception (SerializationInfo info, StreamingContext sc)
  30. {
  31. if (info == null){
  32. throw new ArgumentNullException ("info");
  33. }
  34. // TODO: Implement the restoration of an Exception
  35. // from a stream.
  36. }
  37. public Exception (string msg, Exception e)
  38. {
  39. inner_exception = e;
  40. message = msg;
  41. }
  42. public Exception InnerException {
  43. get {
  44. return inner_exception;
  45. }
  46. }
  47. public string HelpLink {
  48. get {
  49. return help_link;
  50. }
  51. set {
  52. help_link = value;
  53. }
  54. }
  55. protected int HResult {
  56. get {
  57. return hresult;
  58. }
  59. set {
  60. hresult = value;
  61. }
  62. }
  63. public string Message {
  64. get {
  65. return message;
  66. }
  67. }
  68. public string Source {
  69. get {
  70. // TODO: if source is null, we must return
  71. // the name of the assembly where the error
  72. // originated.
  73. return source;
  74. }
  75. set {
  76. source = value;
  77. }
  78. }
  79. public string StackTrace {
  80. get {
  81. return stack_trace;
  82. }
  83. }
  84. public MethodBase TargetSite {
  85. get {
  86. // TODO: Implement this.
  87. return null;
  88. }
  89. }
  90. public virtual Exception GetBaseException ()
  91. {
  92. Exception inner = inner_exception;
  93. while (inner != null){
  94. if (inner.InnerException != null)
  95. inner = inner.InnerException;
  96. else
  97. return inner;
  98. }
  99. return null;
  100. }
  101. public virtual void GetObjectData (SerializationInfo info, StreamingContext context)
  102. {
  103. // TODO: implement me.
  104. }
  105. public override string ToString ()
  106. {
  107. return this.GetType ().FullName + "\n" +
  108. message +
  109. GetBaseException ().GetType ().FullName +
  110. stack_trace;
  111. }
  112. }
  113. }