2
0

ExceptionUtils.cs 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397
  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. namespace Microsoft.VisualBasic.CompilerServices {
  33. [StandardModule, StructLayout(LayoutKind.Auto), EditorBrowsable(EditorBrowsableState.Never)]
  34. sealed public class ExceptionUtils {
  35. private ExceptionUtils () {}
  36. internal const int E_NOTIMPL = -2147467263;
  37. internal const int E_NOINTERFACE = -2147467262;
  38. internal const int E_ABORT = -2147467260;
  39. internal const int DISP_E_UNKNOWNINTERFACE = -2147352575;
  40. internal const int DISP_E_MEMBERNOTFOUND = -2147352573;
  41. internal const int DISP_E_PARAMNOTFOUND = -2147352572;
  42. internal const int DISP_E_TYPEMISMATCH = -2147352571;
  43. internal const int DISP_E_UNKNOWNNAME = -2147352570;
  44. internal const int DISP_E_NONAMEDARGS = -2147352569;
  45. internal const int DISP_E_BADVARTYPE = -2147352568;
  46. internal const int DISP_E_OVERFLOW = -2147352566;
  47. internal const int DISP_E_BADINDEX = -2147352565;
  48. internal const int DISP_E_UNKNOWNLCID = -2147352564;
  49. internal const int DISP_E_ARRAYISLOCKED = -2147352563;
  50. internal const int DISP_E_BADPARAMCOUNT = -2147352562;
  51. internal const int DISP_E_PARAMNOTOPTIONAL = -2147352561;
  52. internal const int DISP_E_NOTACOLLECTION = -2147352559;
  53. internal const int DISP_E_DIVBYZERO = -2147352558;
  54. internal const int TYPE_E_BUFFERTOOSMALL = -2147319786;
  55. internal const int TYPE_E_INVDATAREAD = -2147319784;
  56. internal const int TYPE_E_UNSUPFORMAT = -2147319783;
  57. internal const int TYPE_E_REGISTRYACCESS = -2147319780;
  58. internal const int TYPE_E_LIBNOTREGISTERED = -2147319779;
  59. internal const int TYPE_E_UNDEFINEDTYPE = -2147319769;
  60. internal const int TYPE_E_QUALIFIEDNAMEDISALLOWED = -2147319768;
  61. internal const int TYPE_E_INVALIDSTATE = -2147319767;
  62. internal const int TYPE_E_WRONGTYPEKIND = -2147319766;
  63. internal const int TYPE_E_ELEMENTNOTFOUND = -2147319765;
  64. internal const int TYPE_E_AMBIGUOUSNAME = -2147319764;
  65. internal const int TYPE_E_NAMECONFLICT = -2147319763;
  66. internal const int TYPE_E_UNKNOWNLCID = -2147319762;
  67. internal const int TYPE_E_DLLFUNCTIONNOTFOUND = -2147319761;
  68. internal const int TYPE_E_BADMODULEKIND = -2147317571;
  69. internal const int TYPE_E_SIZETOOBIG = -2147317563;
  70. internal const int TYPE_E_TYPEMISMATCH = -2147316576;
  71. internal const int TYPE_E_OUTOFBOUNDS = -2147316575;
  72. internal const int TYPE_E_IOERROR = -2147316574;
  73. internal const int TYPE_E_CANTCREATETMPFILE = -2147316573;
  74. internal const int TYPE_E_CANTLOADLIBRARY = -2147312566;
  75. internal const int TYPE_E_INCONSISTENTPROPFUNCS = -2147312509;
  76. internal const int TYPE_E_CIRCULARTYPE = -2147312508;
  77. internal const int STG_E_INVALIDFUNCTION = -2147287039;
  78. internal const int STG_E_FILENOTFOUND = -2147287038;
  79. internal const int STG_E_PATHNOTFOUND = -2147287037;
  80. internal const int STG_E_TOOMANYOPENFILES = -2147287036;
  81. internal const int STG_E_ACCESSDENIED = -2147287035;
  82. internal const int STG_E_INVALIDHANDLE = -2147287034;
  83. internal const int STG_E_INSUFFICIENTMEMORY = -2147287032;
  84. internal const int STG_E_NOMOREFILES = -2147287022;
  85. internal const int STG_E_DISKISWRITEPROTECTED = -2147287021;
  86. internal const int STG_E_SEEKERROR = -2147287015;
  87. internal const int STG_E_WRITEFAULT = -2147287011;
  88. internal const int STG_E_READFAULT = -2147287010;
  89. internal const int STG_E_SHAREVIOLATION = -2147287008;
  90. internal const int STG_E_LOCKVIOLATION = -2147287007;
  91. internal const int STG_E_FILEALREADYEXISTS = -2147286960;
  92. internal const int STG_E_MEDIUMFULL = -2147286928;
  93. internal const int STG_E_INVALIDHEADER = -2147286789;
  94. internal const int STG_E_INVALIDNAME = -2147286788;
  95. internal const int STG_E_UNKNOWN = -2147286787;
  96. internal const int STG_E_UNIMPLEMENTEDFUNCTION = -2147286786;
  97. internal const int STG_E_INUSE = -2147286784;
  98. internal const int STG_E_NOTCURRENT = -2147286783;
  99. internal const int STG_E_REVERTED = -2147286782;
  100. internal const int STG_E_CANTSAVE = -2147286781;
  101. internal const int STG_E_OLDFORMAT = -2147286780;
  102. internal const int STG_E_OLDDLL = -2147286779;
  103. internal const int STG_E_SHAREREQUIRED = -2147286778;
  104. internal const int STG_E_NOTFILEBASEDSTORAGE = -2147286777;
  105. internal const int STG_E_EXTANTMARSHALLINGS = -2147286776;
  106. internal const int CLASS_E_NOTLICENSED = -2147221230;
  107. internal const int REGDB_E_CLASSNOTREG = -2147221164;
  108. internal const int MK_E_UNAVAILABLE = -2147221021;
  109. internal const int MK_E_INVALIDEXTENSION = -2147221018;
  110. internal const int MK_E_CANTOPENFILE = -2147221014;
  111. internal const int CO_E_CLASSSTRING = -2147221005;
  112. internal const int CO_E_APPNOTFOUND = -2147221003;
  113. internal const int CO_E_APPDIDNTREG = -2147220994;
  114. internal const int E_ACCESSDENIED = -2147024891;
  115. internal const int E_OUTOFMEMORY = -2147024882;
  116. internal const int E_INVALIDARG = -2147024809;
  117. internal const int CO_E_SERVER_EXEC_FAILURE = -2146959355;
  118. private static Hashtable _dotNetToVBMap = new Hashtable();
  119. private static Hashtable _vbToDotNetClassMap = new Hashtable();
  120. static ExceptionUtils() {
  121. // initializing the hash map that maps vb exception number to .NET exception classes
  122. _vbToDotNetClassMap.Add(VBErrors.ReturnWOGoSub, typeof(InvalidOperationException));
  123. _vbToDotNetClassMap.Add(VBErrors.ResumeWOErr, typeof(InvalidOperationException));
  124. _vbToDotNetClassMap.Add(VBErrors.CantUseNull, typeof(InvalidOperationException));
  125. _vbToDotNetClassMap.Add(VBErrors.DoesntImplementICollection, typeof(InvalidOperationException));
  126. _vbToDotNetClassMap.Add(VBErrors.IllegalFuncCall, typeof(ArgumentException));
  127. _vbToDotNetClassMap.Add(VBErrors.NamedArgsNotSupported, typeof(ArgumentException));
  128. _vbToDotNetClassMap.Add(VBErrors.NamedParamNotFound, typeof(ArgumentException));
  129. _vbToDotNetClassMap.Add(VBErrors.ParameterNotOptional, typeof(ArgumentException));
  130. _vbToDotNetClassMap.Add(VBErrors.OLENoPropOrMethod, typeof(MissingMemberException));
  131. _vbToDotNetClassMap.Add(VBErrors.Overflow, typeof(OverflowException));
  132. _vbToDotNetClassMap.Add(VBErrors.OutOfMemory, typeof(OutOfMemoryException));
  133. _vbToDotNetClassMap.Add(VBErrors.OutOfStrSpace, typeof(OutOfMemoryException));
  134. _vbToDotNetClassMap.Add(VBErrors.OutOfBounds, typeof(IndexOutOfRangeException));
  135. _vbToDotNetClassMap.Add(VBErrors.DivByZero, typeof(DivideByZeroException));
  136. _vbToDotNetClassMap.Add(VBErrors.TypeMismatch, typeof(InvalidCastException));
  137. _vbToDotNetClassMap.Add(VBErrors.OutOfStack, typeof(StackOverflowException));
  138. _vbToDotNetClassMap.Add(VBErrors.DLLLoadErr, typeof(TypeLoadException));
  139. _vbToDotNetClassMap.Add(VBErrors.FileNotFound, typeof(FileNotFoundException));
  140. _vbToDotNetClassMap.Add(VBErrors.EndOfFile, typeof(EndOfStreamException));
  141. _vbToDotNetClassMap.Add(VBErrors.BadFileNameOrNumber, typeof(IOException));
  142. _vbToDotNetClassMap.Add(VBErrors.BadFileMode, typeof(IOException));
  143. _vbToDotNetClassMap.Add(VBErrors.IOError, typeof(IOException));
  144. _vbToDotNetClassMap.Add(VBErrors.FileAlreadyExists, typeof(IOException));
  145. _vbToDotNetClassMap.Add(VBErrors.FileAlreadyOpen, typeof(IOException));
  146. _vbToDotNetClassMap.Add(VBErrors.BadRecordLen, typeof(IOException));
  147. _vbToDotNetClassMap.Add(VBErrors.DiskFull, typeof(IOException));
  148. _vbToDotNetClassMap.Add(VBErrors.BadRecordNum, typeof(IOException));
  149. _vbToDotNetClassMap.Add(VBErrors.TooManyFiles, typeof(IOException));
  150. _vbToDotNetClassMap.Add(VBErrors.DevUnavailable, typeof(IOException));
  151. _vbToDotNetClassMap.Add(VBErrors.PermissionDenied, typeof(IOException));
  152. _vbToDotNetClassMap.Add(VBErrors.DiskNotReady, typeof(IOException));
  153. _vbToDotNetClassMap.Add(VBErrors.DifferentDrive, typeof(IOException));
  154. _vbToDotNetClassMap.Add(VBErrors.PathFileAccess, typeof(IOException));
  155. _vbToDotNetClassMap.Add(VBErrors.PathNotFound, typeof(FileNotFoundException));
  156. _vbToDotNetClassMap.Add(VBErrors.OLEFileNotFound, typeof(FileNotFoundException));
  157. _vbToDotNetClassMap.Add(VBErrors.ObjNotSet, typeof(NullReferenceException));
  158. _vbToDotNetClassMap.Add(VBErrors.PropertyNotFound, typeof(MissingFieldException));
  159. _vbToDotNetClassMap.Add(VBErrors.CantCreateObject, typeof(Exception));
  160. _vbToDotNetClassMap.Add(VBErrors.ServerNotFound, typeof(Exception));
  161. // initializing the hash map that maps .NET exception number to VB exception number
  162. _dotNetToVBMap.Add(ExceptionUtils.E_NOTIMPL,VBErrors.NotYetImplemented);
  163. _dotNetToVBMap.Add(ExceptionUtils.E_NOINTERFACE,VBErrors.OLENotSupported);
  164. _dotNetToVBMap.Add(ExceptionUtils.E_ABORT,VBErrors.Abort);
  165. _dotNetToVBMap.Add(ExceptionUtils.DISP_E_UNKNOWNINTERFACE,VBErrors.OLENoPropOrMethod);
  166. _dotNetToVBMap.Add(ExceptionUtils.DISP_E_MEMBERNOTFOUND,VBErrors.OLENoPropOrMethod);
  167. _dotNetToVBMap.Add(ExceptionUtils.DISP_E_PARAMNOTFOUND,VBErrors.NamedParamNotFound);
  168. _dotNetToVBMap.Add(ExceptionUtils.DISP_E_TYPEMISMATCH,VBErrors.TypeMismatch);
  169. _dotNetToVBMap.Add(ExceptionUtils.DISP_E_UNKNOWNNAME,VBErrors.OLENoPropOrMethod);
  170. _dotNetToVBMap.Add(ExceptionUtils.DISP_E_NONAMEDARGS,VBErrors.NamedArgsNotSupported);
  171. _dotNetToVBMap.Add(ExceptionUtils.DISP_E_BADVARTYPE,VBErrors.InvalidTypeLibVariable);
  172. _dotNetToVBMap.Add(ExceptionUtils.DISP_E_OVERFLOW,VBErrors.Overflow);
  173. _dotNetToVBMap.Add(ExceptionUtils.DISP_E_BADINDEX,VBErrors.OutOfBounds);
  174. _dotNetToVBMap.Add(ExceptionUtils.DISP_E_UNKNOWNLCID,VBErrors.LocaleSettingNotSupported);
  175. _dotNetToVBMap.Add(ExceptionUtils.DISP_E_ARRAYISLOCKED,VBErrors.ArrayLocked);
  176. _dotNetToVBMap.Add(ExceptionUtils.DISP_E_BADPARAMCOUNT,VBErrors.FuncArityMismatch);
  177. _dotNetToVBMap.Add(ExceptionUtils.DISP_E_NOTACOLLECTION,VBErrors.NotEnum);
  178. _dotNetToVBMap.Add(ExceptionUtils.DISP_E_DIVBYZERO,VBErrors.DivByZero);
  179. _dotNetToVBMap.Add(ExceptionUtils.TYPE_E_BUFFERTOOSMALL,VBErrors.BufferTooSmall);
  180. _dotNetToVBMap.Add(-2147319785,VBErrors.IdentNotMember);
  181. _dotNetToVBMap.Add(ExceptionUtils.TYPE_E_INVDATAREAD,VBErrors.InvDataRead);
  182. _dotNetToVBMap.Add(ExceptionUtils.TYPE_E_UNSUPFORMAT,VBErrors.UnsupFormat);
  183. _dotNetToVBMap.Add(ExceptionUtils.TYPE_E_REGISTRYACCESS,VBErrors.RegistryAccess);
  184. _dotNetToVBMap.Add(ExceptionUtils.TYPE_E_LIBNOTREGISTERED,VBErrors.LibNotRegistered);
  185. _dotNetToVBMap.Add(ExceptionUtils.TYPE_E_UNDEFINEDTYPE,VBErrors.UndefinedType);
  186. _dotNetToVBMap.Add(ExceptionUtils.TYPE_E_QUALIFIEDNAMEDISALLOWED,VBErrors.QualifiedNameDisallowed);
  187. _dotNetToVBMap.Add(ExceptionUtils.TYPE_E_INVALIDSTATE,VBErrors.InvalidState);
  188. _dotNetToVBMap.Add(ExceptionUtils.TYPE_E_WRONGTYPEKIND,VBErrors.WrongTypeKind);
  189. _dotNetToVBMap.Add(ExceptionUtils.TYPE_E_ELEMENTNOTFOUND,VBErrors.ElementNotFound);
  190. _dotNetToVBMap.Add(ExceptionUtils.TYPE_E_AMBIGUOUSNAME,VBErrors.AmbiguousName);
  191. _dotNetToVBMap.Add(ExceptionUtils.TYPE_E_NAMECONFLICT,VBErrors.ModNameConflict);
  192. _dotNetToVBMap.Add(ExceptionUtils.TYPE_E_UNKNOWNLCID,VBErrors.UnknownLcid);
  193. _dotNetToVBMap.Add(ExceptionUtils.TYPE_E_DLLFUNCTIONNOTFOUND,VBErrors.InvalidDllFunctionName);
  194. _dotNetToVBMap.Add(ExceptionUtils.TYPE_E_BADMODULEKIND,VBErrors.BadModuleKind);
  195. _dotNetToVBMap.Add(ExceptionUtils.TYPE_E_SIZETOOBIG,VBErrors.SizeTooBig);
  196. _dotNetToVBMap.Add(ExceptionUtils.TYPE_E_TYPEMISMATCH,VBErrors.TypeMismatch);
  197. _dotNetToVBMap.Add(ExceptionUtils.TYPE_E_OUTOFBOUNDS,VBErrors.OutOfBounds);
  198. _dotNetToVBMap.Add(ExceptionUtils.TYPE_E_IOERROR,VBErrors.TypeMismatch);
  199. _dotNetToVBMap.Add(ExceptionUtils.TYPE_E_CANTCREATETMPFILE,VBErrors.CantCreateTmpFile);
  200. _dotNetToVBMap.Add(ExceptionUtils.TYPE_E_CANTLOADLIBRARY,VBErrors.DLLLoadErr);
  201. _dotNetToVBMap.Add(ExceptionUtils.TYPE_E_INCONSISTENTPROPFUNCS,VBErrors.InconsistentPropFuncs);
  202. _dotNetToVBMap.Add(ExceptionUtils.TYPE_E_CIRCULARTYPE,VBErrors.CircularType);
  203. _dotNetToVBMap.Add(ExceptionUtils.STG_E_INVALIDFUNCTION,VBErrors.BadFunctionId);
  204. _dotNetToVBMap.Add(ExceptionUtils.STG_E_FILENOTFOUND,VBErrors.FileNotFound);
  205. _dotNetToVBMap.Add(ExceptionUtils.STG_E_PATHNOTFOUND,VBErrors.PathNotFound);
  206. _dotNetToVBMap.Add(ExceptionUtils.STG_E_TOOMANYOPENFILES,VBErrors.TooManyFiles);
  207. _dotNetToVBMap.Add(ExceptionUtils.STG_E_ACCESSDENIED,VBErrors.PermissionDenied);
  208. _dotNetToVBMap.Add(ExceptionUtils.STG_E_INVALIDHANDLE,VBErrors.ReadFault);
  209. _dotNetToVBMap.Add(ExceptionUtils.STG_E_INSUFFICIENTMEMORY,VBErrors.OutOfMemory);
  210. _dotNetToVBMap.Add(ExceptionUtils.STG_E_NOMOREFILES,VBErrors.TooManyFiles);
  211. _dotNetToVBMap.Add(ExceptionUtils.STG_E_DISKISWRITEPROTECTED,VBErrors.PermissionDenied);
  212. _dotNetToVBMap.Add(ExceptionUtils.STG_E_SEEKERROR,VBErrors.SeekErr);
  213. _dotNetToVBMap.Add(ExceptionUtils.STG_E_WRITEFAULT,VBErrors.ReadFault);
  214. _dotNetToVBMap.Add(ExceptionUtils.STG_E_READFAULT,VBErrors.ReadFault);
  215. _dotNetToVBMap.Add(ExceptionUtils.STG_E_SHAREVIOLATION,VBErrors.PathFileAccess);
  216. _dotNetToVBMap.Add(ExceptionUtils.STG_E_LOCKVIOLATION,VBErrors.PermissionDenied);
  217. _dotNetToVBMap.Add(ExceptionUtils.STG_E_FILEALREADYEXISTS,VBErrors.PathFileAccess);
  218. _dotNetToVBMap.Add(ExceptionUtils.STG_E_MEDIUMFULL,VBErrors.DiskFull);
  219. _dotNetToVBMap.Add(ExceptionUtils.STG_E_INVALIDHEADER,VBErrors.InvDataRead);
  220. _dotNetToVBMap.Add(ExceptionUtils.STG_E_INVALIDNAME,VBErrors.FileNotFound);
  221. _dotNetToVBMap.Add(ExceptionUtils.STG_E_UNKNOWN,VBErrors.InvDataRead);
  222. _dotNetToVBMap.Add(ExceptionUtils.STG_E_UNIMPLEMENTEDFUNCTION,VBErrors.NotYetImplemented);
  223. _dotNetToVBMap.Add(ExceptionUtils.STG_E_INUSE,VBErrors.PermissionDenied);
  224. _dotNetToVBMap.Add(ExceptionUtils.STG_E_NOTCURRENT,VBErrors.PermissionDenied);
  225. _dotNetToVBMap.Add(ExceptionUtils.STG_E_REVERTED,VBErrors.WriteFault);
  226. _dotNetToVBMap.Add(ExceptionUtils.STG_E_CANTSAVE,VBErrors.IOError);
  227. _dotNetToVBMap.Add(ExceptionUtils.STG_E_OLDFORMAT,VBErrors.UnsupFormat);
  228. _dotNetToVBMap.Add(ExceptionUtils.STG_E_OLDDLL,VBErrors.UnsupFormat);
  229. _dotNetToVBMap.Add(ExceptionUtils.STG_E_SHAREREQUIRED,32789);
  230. _dotNetToVBMap.Add(ExceptionUtils.STG_E_NOTFILEBASEDSTORAGE,VBErrors.UnsupFormat);
  231. _dotNetToVBMap.Add(ExceptionUtils.STG_E_EXTANTMARSHALLINGS,VBErrors.UnsupFormat);
  232. _dotNetToVBMap.Add(ExceptionUtils.CLASS_E_NOTLICENSED,VBErrors.CantCreateObject);
  233. _dotNetToVBMap.Add(ExceptionUtils.REGDB_E_CLASSNOTREG,VBErrors.CantCreateObject);
  234. _dotNetToVBMap.Add(ExceptionUtils.MK_E_UNAVAILABLE,VBErrors.CantCreateObject);
  235. _dotNetToVBMap.Add(ExceptionUtils.MK_E_INVALIDEXTENSION,VBErrors.OLEFileNotFound);
  236. _dotNetToVBMap.Add(ExceptionUtils.MK_E_CANTOPENFILE,VBErrors.OLEFileNotFound);
  237. _dotNetToVBMap.Add(ExceptionUtils.CO_E_CLASSSTRING,VBErrors.CantCreateObject);
  238. _dotNetToVBMap.Add(ExceptionUtils.CO_E_APPNOTFOUND,VBErrors.CantCreateObject);
  239. _dotNetToVBMap.Add(ExceptionUtils.CO_E_APPDIDNTREG,VBErrors.CantCreateObject);
  240. _dotNetToVBMap.Add(ExceptionUtils.E_ACCESSDENIED,VBErrors.PermissionDenied);
  241. _dotNetToVBMap.Add(ExceptionUtils.E_OUTOFMEMORY,VBErrors.OutOfMemory);
  242. _dotNetToVBMap.Add(ExceptionUtils.E_INVALIDARG,VBErrors.IllegalFuncCall);
  243. _dotNetToVBMap.Add(-2147023174,VBErrors.ServerNotFound);
  244. _dotNetToVBMap.Add(ExceptionUtils.CO_E_SERVER_EXEC_FAILURE,VBErrors.CantCreateObject);
  245. // new .NET values
  246. _dotNetToVBMap.Add(-2146233080,VBErrors.OutOfBounds);//IndexOutOfRangeException
  247. _dotNetToVBMap.Add(-2146233065,VBErrors.OutOfBounds);//RankException
  248. _dotNetToVBMap.Add(-2147467261,VBErrors.ObjNotSet);//NullPointerException
  249. _dotNetToVBMap.Add(-2146233066,VBErrors.Overflow);//OverflowException
  250. _dotNetToVBMap.Add(-2146233048,VBErrors.Overflow);//NotFiniteNumberException
  251. _dotNetToVBMap.Add(-2146233067,VBErrors.TypeMismatch);//NotSupportedException
  252. _dotNetToVBMap.Add(-2146233070,VBErrors.OLENoPropOrMethod);//MissingMemberException
  253. _dotNetToVBMap.Add(-2146233053,VBErrors.InvalidDllFunctionName);//EntryPointNotFoundException
  254. _dotNetToVBMap.Add(-2146233054,VBErrors.CantCreateObject);//TypeLoadException
  255. _dotNetToVBMap.Add(-2146233033,VBErrors.TypeMismatch);//FormatException
  256. _dotNetToVBMap.Add(-2147024893,VBErrors.PathNotFound);//DirectoryNotFoundException
  257. _dotNetToVBMap.Add(-2146232800,VBErrors.IOError);//IOException
  258. _dotNetToVBMap.Add(-2147024894,VBErrors.FileNotFound);//FileNotFoundException
  259. }
  260. internal static int getVBFromDotNet(int number)
  261. {
  262. return (int) _dotNetToVBMap[number];
  263. }
  264. internal static int fromDotNetToVB(int number)
  265. {
  266. if (number > 0)
  267. return 0;
  268. if ((number & 536805376) == 655360)
  269. return number & 65535;
  270. if(_dotNetToVBMap.Contains (number))
  271. return (int) _dotNetToVBMap[number];
  272. else
  273. return number;
  274. }
  275. internal static Exception BuildException(int number, string description, ref bool VBDefinedError)
  276. {
  277. if (number != 0) {
  278. VBDefinedError = true;
  279. Type exceptionType = (Type) _vbToDotNetClassMap[number];
  280. if (exceptionType != null)
  281. {
  282. try
  283. {
  284. ConstructorInfo ci = exceptionType.GetConstructor(new Type [] {typeof(string)});
  285. return (Exception)ci.Invoke(new object[]{description});
  286. }
  287. catch (Exception e)
  288. {
  289. //Here should be Tracing !!!
  290. // Console.WriteLine("Failed to initiate exception in ExceptionUtils.BuildException with number =" + number);
  291. // e.printStackTrace();
  292. }
  293. }
  294. VBDefinedError = false;
  295. return new Exception(description);
  296. }
  297. return null;
  298. }
  299. /**
  300. * This method builds description string from resource file, replace given parameter
  301. * in the description string and throws .NET exception according to the given number
  302. * @param hr number of VB exception
  303. * @param param1 parameter of message string
  304. */
  305. internal static void ThrowException1(int hr, string param1) {
  306. //TODO: delete or convert???
  307. //string str = "";
  308. // if (hr > 0 && hr <= 65535)
  309. //
  310. // //str = VBUtils.GetResourceString(hr, param1);
  311. //
  312. // throw VbMakeExceptionEx(hr, str);
  313. }
  314. /**
  315. * This method retrives exception message from the resource file and returns
  316. * .NET exception that relevent to given number.
  317. * @param hr
  318. * @return java.lang.Exception
  319. */
  320. internal static Exception VbMakeException(int hr)
  321. {
  322. string str = "";
  323. if (hr > 0 && hr <= 65535) {
  324. str = VBUtils.GetResourceString(hr);
  325. if (str == null)
  326. str = VBUtils.GetResourceString(95);
  327. }
  328. return VbMakeExceptionEx(hr, str);
  329. }
  330. internal static Exception VbMakeException(Exception ex, int hr)
  331. {
  332. Information.Err().SetUnmappedError(hr);
  333. return ex;
  334. }
  335. /**
  336. * This method returns .NET exception that relevant for the given number.
  337. * @param Number
  338. * @param sMsg
  339. * @return java.lang.Exception
  340. */
  341. internal static Exception VbMakeExceptionEx(int number, string msg) {
  342. bool Bool = false;
  343. Exception exp;
  344. exp = ExceptionUtils.BuildException(number, msg, ref Bool);
  345. if(Bool == true)
  346. Information.Err().SetUnmappedError(number);
  347. return exp;
  348. }
  349. }
  350. }