* Interaction.cs :
[mono.git] / mcs / class / Microsoft.VisualBasic / Microsoft.VisualBasic.CompilerServices / ExceptionUtils.cs
1  /*
2   * Copyright (c) 2002-2003 Mainsoft Corporation.
3   * Copyright (C) 2004 Novell, Inc (http://www.novell.com)
4   *
5   * Permission is hereby granted, free of charge, to any person obtaining a
6   * copy of this software and associated documentation files (the "Software"),
7   * to deal in the Software without restriction, including without limitation
8   * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9   * and/or sell copies of the Software, and to permit persons to whom the
10   * Software is furnished to do so, subject to the following conditions:
11   * 
12   * The above copyright notice and this permission notice shall be included in
13   * all copies or substantial portions of the Software.
14   * 
15   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20   * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21   * DEALINGS IN THE SOFTWARE.
22   */
23 /**
24  * This class allows to map VB6 exception number to the .NET exception.
25  */
26 using System;
27 using System.Collections;
28 using System.Reflection;
29 using System.IO;
30 using System.ComponentModel;
31 using System.Runtime.InteropServices;
32
33 namespace Microsoft.VisualBasic.CompilerServices {
34         [StandardModule, StructLayout(LayoutKind.Auto), EditorBrowsable(EditorBrowsableState.Never)] 
35         sealed public class ExceptionUtils {
36                 private ExceptionUtils () {}
37
38                 internal const int E_NOTIMPL = -2147467263;
39                 internal const int E_NOINTERFACE = -2147467262;
40                 internal const int E_ABORT = -2147467260;
41                 internal const int DISP_E_UNKNOWNINTERFACE = -2147352575;
42                 internal const int DISP_E_MEMBERNOTFOUND = -2147352573;
43                 internal const int DISP_E_PARAMNOTFOUND = -2147352572;
44                 internal const int DISP_E_TYPEMISMATCH = -2147352571;
45                 internal const int DISP_E_UNKNOWNNAME = -2147352570;
46                 internal const int DISP_E_NONAMEDARGS = -2147352569;
47                 internal const int DISP_E_BADVARTYPE = -2147352568;
48                 internal const int DISP_E_OVERFLOW = -2147352566;
49                 internal const int DISP_E_BADINDEX = -2147352565;
50                 internal const int DISP_E_UNKNOWNLCID = -2147352564;
51                 internal const int DISP_E_ARRAYISLOCKED = -2147352563;
52                 internal const int DISP_E_BADPARAMCOUNT = -2147352562;
53                 internal const int DISP_E_PARAMNOTOPTIONAL = -2147352561;
54                 internal const int DISP_E_NOTACOLLECTION = -2147352559;
55                 internal const int DISP_E_DIVBYZERO = -2147352558;
56                 internal const int TYPE_E_BUFFERTOOSMALL = -2147319786;
57                 internal const int TYPE_E_INVDATAREAD = -2147319784;
58                 internal const int TYPE_E_UNSUPFORMAT = -2147319783;
59                 internal const int TYPE_E_REGISTRYACCESS = -2147319780;
60                 internal const int TYPE_E_LIBNOTREGISTERED = -2147319779;
61                 internal const int TYPE_E_UNDEFINEDTYPE = -2147319769;
62                 internal const int TYPE_E_QUALIFIEDNAMEDISALLOWED = -2147319768;
63                 internal const int TYPE_E_INVALIDSTATE = -2147319767;
64                 internal const int TYPE_E_WRONGTYPEKIND = -2147319766;
65                 internal const int TYPE_E_ELEMENTNOTFOUND = -2147319765;
66                 internal const int TYPE_E_AMBIGUOUSNAME = -2147319764;
67                 internal const int TYPE_E_NAMECONFLICT = -2147319763;
68                 internal const int TYPE_E_UNKNOWNLCID = -2147319762;
69                 internal const int TYPE_E_DLLFUNCTIONNOTFOUND = -2147319761;
70                 internal const int TYPE_E_BADMODULEKIND = -2147317571;
71                 internal const int TYPE_E_SIZETOOBIG = -2147317563;
72                 internal const int TYPE_E_TYPEMISMATCH = -2147316576;
73                 internal const int TYPE_E_OUTOFBOUNDS = -2147316575;
74                 internal const int TYPE_E_IOERROR = -2147316574;
75                 internal const int TYPE_E_CANTCREATETMPFILE = -2147316573;
76                 internal const int TYPE_E_CANTLOADLIBRARY = -2147312566;
77                 internal const int TYPE_E_INCONSISTENTPROPFUNCS = -2147312509;
78                 internal const int TYPE_E_CIRCULARTYPE = -2147312508;
79                 internal const int STG_E_INVALIDFUNCTION = -2147287039;
80                 internal const int STG_E_FILENOTFOUND = -2147287038;
81                 internal const int STG_E_PATHNOTFOUND = -2147287037;
82                 internal const int STG_E_TOOMANYOPENFILES = -2147287036;
83                 internal const int STG_E_ACCESSDENIED = -2147287035;
84                 internal const int STG_E_INVALIDHANDLE = -2147287034;
85                 internal const int STG_E_INSUFFICIENTMEMORY = -2147287032;
86                 internal const int STG_E_NOMOREFILES = -2147287022;
87                 internal const int STG_E_DISKISWRITEPROTECTED = -2147287021;
88                 internal const int STG_E_SEEKERROR = -2147287015;
89                 internal const int STG_E_WRITEFAULT = -2147287011;
90                 internal const int STG_E_READFAULT = -2147287010;
91                 internal const int STG_E_SHAREVIOLATION = -2147287008;
92                 internal const int STG_E_LOCKVIOLATION = -2147287007;
93                 internal const int STG_E_FILEALREADYEXISTS = -2147286960;
94                 internal const int STG_E_MEDIUMFULL = -2147286928;
95                 internal const int STG_E_INVALIDHEADER = -2147286789;
96                 internal const int STG_E_INVALIDNAME = -2147286788;
97                 internal const int STG_E_UNKNOWN = -2147286787;
98                 internal const int STG_E_UNIMPLEMENTEDFUNCTION = -2147286786;
99                 internal const int STG_E_INUSE = -2147286784;
100                 internal const int STG_E_NOTCURRENT = -2147286783;
101                 internal const int STG_E_REVERTED = -2147286782;
102                 internal const int STG_E_CANTSAVE = -2147286781;
103                 internal const int STG_E_OLDFORMAT = -2147286780;
104                 internal const int STG_E_OLDDLL = -2147286779;
105                 internal const int STG_E_SHAREREQUIRED = -2147286778;
106                 internal const int STG_E_NOTFILEBASEDSTORAGE = -2147286777;
107                 internal const int STG_E_EXTANTMARSHALLINGS = -2147286776;
108                 internal const int CLASS_E_NOTLICENSED = -2147221230;
109                 internal const int REGDB_E_CLASSNOTREG = -2147221164;
110                 internal const int MK_E_UNAVAILABLE = -2147221021;
111                 internal const int MK_E_INVALIDEXTENSION = -2147221018;
112                 internal const int MK_E_CANTOPENFILE = -2147221014;
113                 internal const int CO_E_CLASSSTRING = -2147221005;
114                 internal const int CO_E_APPNOTFOUND = -2147221003;
115                 internal const int CO_E_APPDIDNTREG = -2147220994;
116                 internal const int E_ACCESSDENIED = -2147024891;
117                 internal const int E_OUTOFMEMORY = -2147024882;
118                 internal const int E_INVALIDARG = -2147024809;
119                 internal const int CO_E_SERVER_EXEC_FAILURE = -2146959355;
120
121                 private static Hashtable _dotNetToVBMap = new Hashtable();
122                 private static Hashtable _vbToDotNetClassMap = new Hashtable();
123
124
125                 static ExceptionUtils() {
126                         // initializing the hash map that maps vb exception number to .NET exception classes
127                         _vbToDotNetClassMap.Add(VBErrors.ReturnWOGoSub, typeof(InvalidOperationException));
128                         _vbToDotNetClassMap.Add(VBErrors.ResumeWOErr, typeof(InvalidOperationException));
129                         _vbToDotNetClassMap.Add(VBErrors.CantUseNull, typeof(InvalidOperationException));
130                         _vbToDotNetClassMap.Add(VBErrors.DoesntImplementICollection, typeof(InvalidOperationException));
131         
132                         _vbToDotNetClassMap.Add(VBErrors.IllegalFuncCall, typeof(ArgumentException));
133                         _vbToDotNetClassMap.Add(VBErrors.NamedArgsNotSupported, typeof(ArgumentException));
134                         _vbToDotNetClassMap.Add(VBErrors.NamedParamNotFound, typeof(ArgumentException));
135                         _vbToDotNetClassMap.Add(VBErrors.ParameterNotOptional, typeof(ArgumentException));
136         
137                         _vbToDotNetClassMap.Add(VBErrors.OLENoPropOrMethod, typeof(MissingMemberException));
138         
139                         _vbToDotNetClassMap.Add(VBErrors.Overflow, typeof(OverflowException));
140         
141                         _vbToDotNetClassMap.Add(VBErrors.OutOfMemory, typeof(OutOfMemoryException));
142                         _vbToDotNetClassMap.Add(VBErrors.OutOfStrSpace, typeof(OutOfMemoryException));
143         
144                         _vbToDotNetClassMap.Add(VBErrors.OutOfBounds, typeof(IndexOutOfRangeException));
145         
146                         _vbToDotNetClassMap.Add(VBErrors.DivByZero, typeof(DivideByZeroException));
147         
148                         _vbToDotNetClassMap.Add(VBErrors.TypeMismatch, typeof(InvalidCastException));
149         
150                         _vbToDotNetClassMap.Add(VBErrors.OutOfStack, typeof(StackOverflowException));
151         
152                         _vbToDotNetClassMap.Add(VBErrors.DLLLoadErr, typeof(TypeLoadException));
153         
154                         _vbToDotNetClassMap.Add(VBErrors.FileNotFound, typeof(FileNotFoundException));
155         
156                         _vbToDotNetClassMap.Add(VBErrors.EndOfFile, typeof(EndOfStreamException));
157         
158                         _vbToDotNetClassMap.Add(VBErrors.BadFileNameOrNumber, typeof(IOException));
159                         _vbToDotNetClassMap.Add(VBErrors.BadFileMode, typeof(IOException));
160                         _vbToDotNetClassMap.Add(VBErrors.IOError, typeof(IOException));
161                         _vbToDotNetClassMap.Add(VBErrors.FileAlreadyExists, typeof(IOException));
162                         _vbToDotNetClassMap.Add(VBErrors.FileAlreadyOpen, typeof(IOException));
163                         _vbToDotNetClassMap.Add(VBErrors.BadRecordLen, typeof(IOException));
164                         _vbToDotNetClassMap.Add(VBErrors.DiskFull, typeof(IOException));
165                         _vbToDotNetClassMap.Add(VBErrors.BadRecordNum, typeof(IOException));
166                         _vbToDotNetClassMap.Add(VBErrors.TooManyFiles, typeof(IOException));
167                         _vbToDotNetClassMap.Add(VBErrors.DevUnavailable, typeof(IOException));
168                         _vbToDotNetClassMap.Add(VBErrors.PermissionDenied, typeof(IOException));
169                         _vbToDotNetClassMap.Add(VBErrors.DiskNotReady, typeof(IOException));
170                         _vbToDotNetClassMap.Add(VBErrors.DifferentDrive, typeof(IOException));
171                         _vbToDotNetClassMap.Add(VBErrors.PathFileAccess, typeof(IOException));
172         
173                         _vbToDotNetClassMap.Add(VBErrors.PathNotFound, typeof(FileNotFoundException));
174                         _vbToDotNetClassMap.Add(VBErrors.OLEFileNotFound, typeof(FileNotFoundException));
175         
176                         _vbToDotNetClassMap.Add(VBErrors.ObjNotSet, typeof(NullReferenceException));
177         
178                         _vbToDotNetClassMap.Add(VBErrors.PropertyNotFound, typeof(MissingFieldException));
179         
180                         _vbToDotNetClassMap.Add(VBErrors.CantCreateObject, typeof(Exception));
181                         _vbToDotNetClassMap.Add(VBErrors.ServerNotFound, typeof(Exception));
182
183                         // initializing the hash map that maps .NET exception number to VB exception number
184                         _dotNetToVBMap.Add(ExceptionUtils.E_NOTIMPL,VBErrors.NotYetImplemented);
185                         _dotNetToVBMap.Add(ExceptionUtils.E_NOINTERFACE,VBErrors.OLENotSupported);
186                         _dotNetToVBMap.Add(ExceptionUtils.E_ABORT,VBErrors.Abort);
187                         _dotNetToVBMap.Add(ExceptionUtils.DISP_E_UNKNOWNINTERFACE,VBErrors.OLENoPropOrMethod);
188                         _dotNetToVBMap.Add(ExceptionUtils.DISP_E_MEMBERNOTFOUND,VBErrors.OLENoPropOrMethod);
189                         _dotNetToVBMap.Add(ExceptionUtils.DISP_E_PARAMNOTFOUND,VBErrors.NamedParamNotFound);
190                         _dotNetToVBMap.Add(ExceptionUtils.DISP_E_TYPEMISMATCH,VBErrors.TypeMismatch);
191                         _dotNetToVBMap.Add(ExceptionUtils.DISP_E_UNKNOWNNAME,VBErrors.OLENoPropOrMethod);
192                         _dotNetToVBMap.Add(ExceptionUtils.DISP_E_NONAMEDARGS,VBErrors.NamedArgsNotSupported);
193                         _dotNetToVBMap.Add(ExceptionUtils.DISP_E_BADVARTYPE,VBErrors.InvalidTypeLibVariable);
194                         _dotNetToVBMap.Add(ExceptionUtils.DISP_E_OVERFLOW,VBErrors.Overflow);
195                         _dotNetToVBMap.Add(ExceptionUtils.DISP_E_BADINDEX,VBErrors.OutOfBounds);
196                         _dotNetToVBMap.Add(ExceptionUtils.DISP_E_UNKNOWNLCID,VBErrors.LocaleSettingNotSupported);
197                         _dotNetToVBMap.Add(ExceptionUtils.DISP_E_ARRAYISLOCKED,VBErrors.ArrayLocked);
198                         _dotNetToVBMap.Add(ExceptionUtils.DISP_E_BADPARAMCOUNT,VBErrors.FuncArityMismatch);
199                         _dotNetToVBMap.Add(ExceptionUtils.DISP_E_NOTACOLLECTION,VBErrors.NotEnum);
200                         _dotNetToVBMap.Add(ExceptionUtils.DISP_E_DIVBYZERO,VBErrors.DivByZero);
201                         _dotNetToVBMap.Add(ExceptionUtils.TYPE_E_BUFFERTOOSMALL,VBErrors.BufferTooSmall);
202                         _dotNetToVBMap.Add(-2147319785,VBErrors.IdentNotMember);
203                         _dotNetToVBMap.Add(ExceptionUtils.TYPE_E_INVDATAREAD,VBErrors.InvDataRead);
204                         _dotNetToVBMap.Add(ExceptionUtils.TYPE_E_UNSUPFORMAT,VBErrors.UnsupFormat);
205                         _dotNetToVBMap.Add(ExceptionUtils.TYPE_E_REGISTRYACCESS,VBErrors.RegistryAccess);
206                         _dotNetToVBMap.Add(ExceptionUtils.TYPE_E_LIBNOTREGISTERED,VBErrors.LibNotRegistered);
207                         _dotNetToVBMap.Add(ExceptionUtils.TYPE_E_UNDEFINEDTYPE,VBErrors.UndefinedType);
208                         _dotNetToVBMap.Add(ExceptionUtils.TYPE_E_QUALIFIEDNAMEDISALLOWED,VBErrors.QualifiedNameDisallowed);
209                         _dotNetToVBMap.Add(ExceptionUtils.TYPE_E_INVALIDSTATE,VBErrors.InvalidState);
210                         _dotNetToVBMap.Add(ExceptionUtils.TYPE_E_WRONGTYPEKIND,VBErrors.WrongTypeKind);
211                         _dotNetToVBMap.Add(ExceptionUtils.TYPE_E_ELEMENTNOTFOUND,VBErrors.ElementNotFound);
212                         _dotNetToVBMap.Add(ExceptionUtils.TYPE_E_AMBIGUOUSNAME,VBErrors.AmbiguousName);
213                         _dotNetToVBMap.Add(ExceptionUtils.TYPE_E_NAMECONFLICT,VBErrors.ModNameConflict);
214                         _dotNetToVBMap.Add(ExceptionUtils.TYPE_E_UNKNOWNLCID,VBErrors.UnknownLcid);
215                         _dotNetToVBMap.Add(ExceptionUtils.TYPE_E_DLLFUNCTIONNOTFOUND,VBErrors.InvalidDllFunctionName);
216                         _dotNetToVBMap.Add(ExceptionUtils.TYPE_E_BADMODULEKIND,VBErrors.BadModuleKind);
217                         _dotNetToVBMap.Add(ExceptionUtils.TYPE_E_SIZETOOBIG,VBErrors.SizeTooBig);
218                         _dotNetToVBMap.Add(ExceptionUtils.TYPE_E_TYPEMISMATCH,VBErrors.TypeMismatch);
219                         _dotNetToVBMap.Add(ExceptionUtils.TYPE_E_OUTOFBOUNDS,VBErrors.OutOfBounds);
220                         _dotNetToVBMap.Add(ExceptionUtils.TYPE_E_IOERROR,VBErrors.TypeMismatch);
221                         _dotNetToVBMap.Add(ExceptionUtils.TYPE_E_CANTCREATETMPFILE,VBErrors.CantCreateTmpFile);
222                         _dotNetToVBMap.Add(ExceptionUtils.TYPE_E_CANTLOADLIBRARY,VBErrors.DLLLoadErr);
223                         _dotNetToVBMap.Add(ExceptionUtils.TYPE_E_INCONSISTENTPROPFUNCS,VBErrors.InconsistentPropFuncs);
224                         _dotNetToVBMap.Add(ExceptionUtils.TYPE_E_CIRCULARTYPE,VBErrors.CircularType);
225                         _dotNetToVBMap.Add(ExceptionUtils.STG_E_INVALIDFUNCTION,VBErrors.BadFunctionId);
226                         _dotNetToVBMap.Add(ExceptionUtils.STG_E_FILENOTFOUND,VBErrors.FileNotFound);
227                         _dotNetToVBMap.Add(ExceptionUtils.STG_E_PATHNOTFOUND,VBErrors.PathNotFound);
228                         _dotNetToVBMap.Add(ExceptionUtils.STG_E_TOOMANYOPENFILES,VBErrors.TooManyFiles);
229                         _dotNetToVBMap.Add(ExceptionUtils.STG_E_ACCESSDENIED,VBErrors.PermissionDenied);
230                         _dotNetToVBMap.Add(ExceptionUtils.STG_E_INVALIDHANDLE,VBErrors.ReadFault);
231                         _dotNetToVBMap.Add(ExceptionUtils.STG_E_INSUFFICIENTMEMORY,VBErrors.OutOfMemory);
232                         _dotNetToVBMap.Add(ExceptionUtils.STG_E_NOMOREFILES,VBErrors.TooManyFiles);
233                         _dotNetToVBMap.Add(ExceptionUtils.STG_E_DISKISWRITEPROTECTED,VBErrors.PermissionDenied);
234                         _dotNetToVBMap.Add(ExceptionUtils.STG_E_SEEKERROR,VBErrors.SeekErr);
235                         _dotNetToVBMap.Add(ExceptionUtils.STG_E_WRITEFAULT,VBErrors.ReadFault);
236                         _dotNetToVBMap.Add(ExceptionUtils.STG_E_READFAULT,VBErrors.ReadFault);
237                         _dotNetToVBMap.Add(ExceptionUtils.STG_E_SHAREVIOLATION,VBErrors.PathFileAccess);
238                         _dotNetToVBMap.Add(ExceptionUtils.STG_E_LOCKVIOLATION,VBErrors.PermissionDenied);
239                         _dotNetToVBMap.Add(ExceptionUtils.STG_E_FILEALREADYEXISTS,VBErrors.PathFileAccess);
240                         _dotNetToVBMap.Add(ExceptionUtils.STG_E_MEDIUMFULL,VBErrors.DiskFull);
241                         _dotNetToVBMap.Add(ExceptionUtils.STG_E_INVALIDHEADER,VBErrors.InvDataRead);
242                         _dotNetToVBMap.Add(ExceptionUtils.STG_E_INVALIDNAME,VBErrors.FileNotFound);
243                         _dotNetToVBMap.Add(ExceptionUtils.STG_E_UNKNOWN,VBErrors.InvDataRead);
244                         _dotNetToVBMap.Add(ExceptionUtils.STG_E_UNIMPLEMENTEDFUNCTION,VBErrors.NotYetImplemented);
245                         _dotNetToVBMap.Add(ExceptionUtils.STG_E_INUSE,VBErrors.PermissionDenied);
246                         _dotNetToVBMap.Add(ExceptionUtils.STG_E_NOTCURRENT,VBErrors.PermissionDenied);
247                         _dotNetToVBMap.Add(ExceptionUtils.STG_E_REVERTED,VBErrors.WriteFault);
248                         _dotNetToVBMap.Add(ExceptionUtils.STG_E_CANTSAVE,VBErrors.IOError);
249                         _dotNetToVBMap.Add(ExceptionUtils.STG_E_OLDFORMAT,VBErrors.UnsupFormat);
250                         _dotNetToVBMap.Add(ExceptionUtils.STG_E_OLDDLL,VBErrors.UnsupFormat);
251                         _dotNetToVBMap.Add(ExceptionUtils.STG_E_SHAREREQUIRED,32789);
252                         _dotNetToVBMap.Add(ExceptionUtils.STG_E_NOTFILEBASEDSTORAGE,VBErrors.UnsupFormat);
253                         _dotNetToVBMap.Add(ExceptionUtils.STG_E_EXTANTMARSHALLINGS,VBErrors.UnsupFormat);
254                         _dotNetToVBMap.Add(ExceptionUtils.CLASS_E_NOTLICENSED,VBErrors.CantCreateObject);
255                         _dotNetToVBMap.Add(ExceptionUtils.REGDB_E_CLASSNOTREG,VBErrors.CantCreateObject);
256                         _dotNetToVBMap.Add(ExceptionUtils.MK_E_UNAVAILABLE,VBErrors.CantCreateObject);
257                         _dotNetToVBMap.Add(ExceptionUtils.MK_E_INVALIDEXTENSION,VBErrors.OLEFileNotFound);
258                         _dotNetToVBMap.Add(ExceptionUtils.MK_E_CANTOPENFILE,VBErrors.OLEFileNotFound);
259                         _dotNetToVBMap.Add(ExceptionUtils.CO_E_CLASSSTRING,VBErrors.CantCreateObject);
260                         _dotNetToVBMap.Add(ExceptionUtils.CO_E_APPNOTFOUND,VBErrors.CantCreateObject);
261                         _dotNetToVBMap.Add(ExceptionUtils.CO_E_APPDIDNTREG,VBErrors.CantCreateObject);
262                         _dotNetToVBMap.Add(ExceptionUtils.E_ACCESSDENIED,VBErrors.PermissionDenied);
263                         _dotNetToVBMap.Add(ExceptionUtils.E_OUTOFMEMORY,VBErrors.OutOfMemory);
264                         _dotNetToVBMap.Add(ExceptionUtils.E_INVALIDARG,VBErrors.IllegalFuncCall);
265                         _dotNetToVBMap.Add(-2147023174,VBErrors.ServerNotFound);
266                         _dotNetToVBMap.Add(ExceptionUtils.CO_E_SERVER_EXEC_FAILURE,VBErrors.CantCreateObject);
267
268                         // new .NET values
269                         _dotNetToVBMap.Add(-2146233080,VBErrors.OutOfBounds);//IndexOutOfRangeException
270                         _dotNetToVBMap.Add(-2146233065,VBErrors.OutOfBounds);//RankException
271                         _dotNetToVBMap.Add(-2147467261,VBErrors.ObjNotSet);//NullPointerException
272                         _dotNetToVBMap.Add(-2146233066,VBErrors.Overflow);//OverflowException
273                         _dotNetToVBMap.Add(-2146233048,VBErrors.Overflow);//NotFiniteNumberException
274                         _dotNetToVBMap.Add(-2146233067,VBErrors.TypeMismatch);//NotSupportedException
275                         _dotNetToVBMap.Add(-2146233070,VBErrors.OLENoPropOrMethod);//MissingMemberException
276                         _dotNetToVBMap.Add(-2146233053,VBErrors.InvalidDllFunctionName);//EntryPointNotFoundException
277                         _dotNetToVBMap.Add(-2146233054,VBErrors.CantCreateObject);//TypeLoadException
278                         _dotNetToVBMap.Add(-2146233033,VBErrors.TypeMismatch);//FormatException
279                         _dotNetToVBMap.Add(-2147024893,VBErrors.PathNotFound);//DirectoryNotFoundException
280                         _dotNetToVBMap.Add(-2146232800,VBErrors.IOError);//IOException
281                         _dotNetToVBMap.Add(-2147024894,VBErrors.FileNotFound);//FileNotFoundException     
282                 }
283
284                 internal static int getVBFromDotNet(int number) 
285                 {
286                         return (int) _dotNetToVBMap[number];
287                 }
288
289                 internal static int fromDotNetToVB(int number) 
290                 {
291                         if (number > 0)
292                                 return 0;
293
294                         if ((number & 536805376) == 655360)
295                                 return number & 65535;
296
297
298                         if(_dotNetToVBMap.Contains (number))
299                                 return (int) _dotNetToVBMap[number];
300                         else
301                                 return number;
302                 }
303
304                 internal static Exception BuildException(int number, string description, ref bool VBDefinedError) 
305                 {
306                         if (number != 0) {
307                                 VBDefinedError = true;
308
309                                 Type exceptionType = (Type) _vbToDotNetClassMap[number];
310
311                                 if (exceptionType != null)
312                                 {
313                                         try
314                                         {
315                                                 ConstructorInfo ci = exceptionType.GetConstructor(new Type [] {typeof(string)});
316                                                 return (Exception)ci.Invoke(new object[]{description});                    
317                                         }
318                                         catch (Exception e)
319                                         {
320                                                 //Here should be Tracing !!!
321                                                 // Console.WriteLine("Failed to initiate exception in ExceptionUtils.BuildException with number =" + number);
322                                                 // e.printStackTrace();
323                                         }
324                                 }
325         
326                                 VBDefinedError = false;
327                                 return new Exception(description);
328                         }
329                         return null;
330                 }
331
332
333
334
335                 /**
336                  * This method builds description string from resource file, replace given parameter
337                  * in the description string and throws .NET exception according to the given number
338                  * @param hr number of VB exception
339                  * @param param1 parameter of message string
340                  */
341                 
342                 internal static void ThrowException1(int hr, string param1) {
343                         //TODO: delete or convert???
344                         //string str = "";
345
346                         //                      if (hr > 0 && hr <= 65535)
347                         //                      
348                         //                              //str = VBUtils.GetResourceString(hr, param1);
349                         //
350                         //                              throw VbMakeExceptionEx(hr, str);
351                 }
352
353                 /**
354                  * This method retrives exception message from the resource file and returns
355                  * .NET exception that relevent to given number.
356                  * @param hr
357                  * @return java.lang.Exception
358                  */
359                 internal static Exception VbMakeException(int hr) 
360                 {
361                         string str = "";
362
363                         if (hr > 0 && hr <= 65535) {
364                                 str = VBUtils.GetResourceString(hr);
365                                 if (str == null)
366                                         str  = VBUtils.GetResourceString(95);
367                         }    
368
369                         return VbMakeExceptionEx(hr, str);
370                 }
371
372                 internal static Exception VbMakeException(Exception ex, int hr)
373                 {
374                         Information.Err().SetUnmappedError(hr);
375                         return ex;
376                 }
377
378                 /**
379                  * This method returns .NET exception that relevant for the given number.
380                  * @param Number
381                  * @param sMsg
382                  * @return java.lang.Exception
383                  */
384
385                 internal static Exception VbMakeExceptionEx(int number, string msg) {
386                         bool Bool = false; 
387                         Exception exp;
388                 
389                         exp = ExceptionUtils.BuildException(number, msg, ref Bool);
390                         if(Bool == true)
391                                 Information.Err().SetUnmappedError(number);
392
393                         return exp;
394                 }
395
396         }
397 }