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