/mcs/class/Microsoft.JScript/Microsoft.JScript/JScriptException.cs

https://github.com/cschlote/mono · C# · 180 lines · 111 code · 40 blank · 29 comment · 35 complexity · b9db65672b174c6bb1f587fe63e1f402 MD5 · raw file

  1. //
  2. // JScriptException.cs:
  3. //
  4. // Author:
  5. // Cesar Lopez Nataren (cesar@ciencias.unam.mx)
  6. //
  7. // (C) 2003, Cesar Lopez Nataren
  8. // (C) 2005, Novell Inc, (http://novell.com)
  9. //
  10. //
  11. // Permission is hereby granted, free of charge, to any person obtaining
  12. // a copy of this software and associated documentation files (the
  13. // "Software"), to deal in the Software without restriction, including
  14. // without limitation the rights to use, copy, modify, merge, publish,
  15. // distribute, sublicense, and/or sell copies of the Software, and to
  16. // permit persons to whom the Software is furnished to do so, subject to
  17. // the following conditions:
  18. //
  19. // The above copyright notice and this permission notice shall be
  20. // included in all copies or substantial portions of the Software.
  21. //
  22. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  23. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  24. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  25. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  26. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  27. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  28. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  29. //
  30. using System;
  31. using Microsoft.Vsa;
  32. using System.Runtime.Serialization;
  33. using System.Text;
  34. namespace Microsoft.JScript {
  35. [Serializable]
  36. public class JScriptException : ApplicationException, IVsaError {
  37. private JSError error_number;
  38. private string user_error = null;
  39. private string extra_data = "";
  40. public JScriptException (JSError errorNumber)
  41. {
  42. error_number = errorNumber;
  43. }
  44. internal JScriptException (JSError errorNumber, string extraData)
  45. {
  46. error_number = errorNumber;
  47. extra_data = extraData;
  48. }
  49. internal JScriptException (string user_err)
  50. {
  51. error_number = JSError.NoError;
  52. user_error = user_err;
  53. }
  54. public string SourceMoniker {
  55. get { throw new NotImplementedException (); }
  56. }
  57. public int StartColumn {
  58. get { throw new NotImplementedException (); }
  59. }
  60. public int Column {
  61. get { throw new NotImplementedException (); }
  62. }
  63. public string Description {
  64. get {
  65. if (error_number == JSError.NoError)
  66. return user_error;
  67. else if (error_number == JSError.ArrayLengthConstructIncorrect)
  68. return "Array length must be zero or a positive integer";
  69. else if (error_number == JSError.PrecisionOutOfRange)
  70. return "The number of fractional digits is out of range";
  71. else if (error_number == JSError.RegExpSyntax)
  72. return "Syntax error in regular expression";
  73. else if (error_number == JSError.TypeMismatch)
  74. return "Unexpected type";
  75. else if (error_number == JSError.BooleanExpected)
  76. return "Invoked Boolean.prototype.toString or Boolean.prototype.valueOf method on non-boolean";
  77. else if (error_number == JSError.NumberExpected)
  78. return "Invoked Number.prototype.toString or Number.prototype.valueOf method on non-number";
  79. else if (error_number == JSError.StringExpected)
  80. return "Invoked String.prototype.toString or String.prototype.valueOf method on non-string";
  81. else if (error_number == JSError.FunctionExpected)
  82. return "Invoked Function.prototype.toString on non-function";
  83. else if (error_number == JSError.AssignmentToReadOnly)
  84. return "Tried to assign to read only property";
  85. else if (error_number == JSError.NotCollection)
  86. return "Object is not a collection";
  87. else {
  88. Console.WriteLine ("JScriptException:get_Message: unknown error_number {0}", error_number);
  89. throw new NotImplementedException ();
  90. }
  91. }
  92. }
  93. public int EndLine {
  94. get { throw new NotImplementedException (); }
  95. }
  96. public int EndColumn {
  97. get { throw new NotImplementedException (); }
  98. }
  99. public int Number {
  100. get { return (int) error_number; }
  101. }
  102. public int ErrorNumber {
  103. get { return (int) error_number; }
  104. }
  105. public override void GetObjectData (SerializationInfo info, StreamingContext context)
  106. {
  107. throw new NotImplementedException ();
  108. }
  109. public int Line {
  110. get { throw new NotImplementedException (); }
  111. }
  112. public string LineText {
  113. get { throw new NotImplementedException (); }
  114. }
  115. public override string Message {
  116. get
  117. {
  118. StringBuilder result = new StringBuilder (Description);
  119. if (extra_data != "") {
  120. result.Append (": ");
  121. result.Append (extra_data);
  122. }
  123. return result.ToString ();
  124. }
  125. }
  126. public int Severity {
  127. get { throw new NotImplementedException (); }
  128. }
  129. public IVsaItem SourceItem {
  130. get { throw new NotImplementedException (); }
  131. }
  132. public override string StackTrace {
  133. get {
  134. return base.StackTrace;
  135. }
  136. }
  137. }
  138. public class NoContextException : ApplicationException
  139. {}
  140. }