//
using System;
+using Microsoft.VisualBasic.CompilerServices;
namespace Microsoft.VisualBasic \r
{
sealed public class ErrObject {
- // Declarations
- int pHelpContext;
- int pLastDllError;
- int pNumber;
- int pErl;
- string pSource;
- string pHelpFile;
- string pDescription;
- System.Exception pException;
- // Constructors
- // Properties
+
+ private System.Exception pException;
+ private int pErl;
+ private int pNumber;
+ private string pSource;
+ private string pDescription;
+ private string pHelpFile;
+ private int pHelpContext;
+
+ private int pLastDllError;
+
+ private bool m_bDontMapException = false;
+ private bool NumberIsSet = false;
+ private bool ClearOnCapture = false;
+ private bool SourceIsSet = false;
+ private bool DescriptionIsSet = false;
+ private bool HelpFileIsSet = false;
+ private bool HelpContextIsSet = false;
+
+ public ErrObject()
+ {
+ Clear();
+ }
+
+ public void Clear ()
+ {
+ pException = null;
+ pErl = 0;
+ pNumber = 0;
+ pSource = "";
+ pDescription = "";
+ pHelpFile = "";
+ pHelpContext = 0;
+
+ m_bDontMapException = false;
+ NumberIsSet = false;
+ ClearOnCapture = false;
+ SourceIsSet = false;
+ DescriptionIsSet = false;
+ HelpFileIsSet = false;
+ HelpContextIsSet = false;
+ ClearOnCapture = true;
+ }
+
+ public void CaptureException (Exception ex)
+ {
+ if(ex == pException)
+ return;
+ if(ClearOnCapture == true)
+ Clear();
+ else
+ ClearOnCapture = true;
+
+ pException = ex;
+ }
+
+ public void CaptureException (Exception ex, int lErl)
+ {
+ CaptureException(ex);
+ pErl = lErl;
+ }
+
+ public Exception CreateException (int Number, String Description)
+ {
+ Exception ex;
+
+ Clear();
+ this.Number = Number;
+ if(Number == 0)
+ throw new ArgumentException(Utils.GetResourceString("Argument_InvalidValue1", "Number"));
+ ex = MapNumberToException(pNumber, Description);
+ this.ClearOnCapture = false;
+ return ex;
+ }
+
+ private String FilterDefaultMessage(String Msg)
+ {
+ if(pException == null)
+ return Msg;
+
+ string Msg1 = Utils.GetResourceString(this.Number);
+
+ if(Msg == null || Msg.Length == 0)
+ return Msg1;
+ else if(String.CompareOrdinal("Exception from HRESULT: 0x", 0, Msg, 0, System.Math.Min(Msg.Length, 26)) == 0) {
+ return (Msg1 != null ? Msg1 : Msg);
+ }
+ else
+ return Msg;
+ }
+
+ private Exception MapNumberToException (int Number, String Description)
+ {
+ bool Ignored = false;
+ return ExceptionUtils.BuildException(Number, Description, ref Ignored);
+ }
+
+
+ // This function needs to be reviewed
+ private int MapExceptionToNumber (Exception ex)
+ {
+ int hResult = 0;
+
+ if(ex is ArgumentException) {
+ hResult = unchecked((int)0x80070057);
+ }
+ else if(ex is ArithmeticException) {
+ if(ex is NotFiniteNumberException) {
+ if((ex as NotFiniteNumberException).OffendingNumber == 0)
+ return 11;
+ else
+ return 6;
+ }
+ else {
+ hResult = unchecked((int)0x80070216);
+ }
+ }
+ else if(ex is ArrayTypeMismatchException) {
+ hResult = unchecked((int)0x80131503);
+ }
+ // else if(exType.Equals(IndexOutOfRangeException)) {
+ // hResult = (exType.Equals(IndexOutOfRangeException)).HResult;
+ // }
+ else if(ex is InvalidCastException) {
+ hResult = unchecked((int)0x80004002);
+ }
+ else if(ex is NotSupportedException) {
+ hResult = unchecked((int)0x80131515);
+ }
+ else if(ex is NullReferenceException) {
+ hResult = unchecked((int)0x80004003);
+ }
+ else if(ex is UnauthorizedAccessException) {
+ hResult = unchecked((int)0x80131500);
+ }
+
+ else {
+ hResult = unchecked((int)0x80004005);
+ }
+
+ hResult = ExceptionUtils.getVBFromDotNet(hResult);
+ if(hResult != 0 )
+ return hResult;
+ else
+ return 5;
+ }
+
+ private void ParseHelpLink (String HelpLink)
+ {
+ int ind;
+
+ if(HelpLink == null || HelpLink.Length == 0) {
+ if(HelpContextIsSet == false)
+ this.HelpContext = 0;
+
+ if (HelpFileIsSet == false)
+ this.HelpFile = "";
+ }
+ else {
+ ind = HelpLink.IndexOf("#");
+
+ if(ind != -1) {
+ if(HelpContextIsSet == false) {
+ if(ind < HelpLink.Length)
+ this.HelpContext = IntegerType.FromString(HelpLink.Substring(ind + 1));
+ else
+ this.HelpContext = 0;
+ }
+ if (HelpFileIsSet == false)
+ this.HelpFile = HelpLink.Substring(0, ind);
+ }
+ else {
+ if (HelpContextIsSet == false)
+ this.HelpContext = 0;
+
+ if (!this.HelpFileIsSet)
+ this.HelpFile = HelpLink;
+ }
+ }
+ }
+
+ public int MapErrorNumber (int Number)
+ {
+ if(Number > 65535)
+ throw new ArgumentException(VBUtils.GetResourceString("Argument_InvalidValue1", "Number"));
+
+
+ if(Number >= 0)
+ return Number;
+ else
+ return ExceptionUtils.fromDotNetToVB(Number);
+ }
+
+ private String MakeHelpLink(String HelpFile, int HelpContext)
+ {
+ return HelpFile + "#" + StringType.FromInteger(HelpContext);
+ }
+
[MonoTODO]
- public System.Int32 HelpContext
+ public void Raise (System.Int32 Number,
+ [System.Runtime.InteropServices.Optional]
+ [System.ComponentModel.DefaultValue(null)] System.Object Source,
+ [System.Runtime.InteropServices.Optional]
+ [System.ComponentModel.DefaultValue(null)] System.Object Description,
+ [System.Runtime.InteropServices.Optional]
+ [System.ComponentModel.DefaultValue(null)] System.Object HelpFile,
+ [System.Runtime.InteropServices.Optional]
+ [System.ComponentModel.DefaultValue(null)] System.Object HelpContext)
{
- get {
- return pHelpContext;
- }
- set {
- pHelpContext = value;
- }
+ Exception e;
+
+ if(Number == 0)
+ throw new ArgumentException(Utils.GetResourceString("Argument_InvalidValue1", "Number"));
+
+ this.Number = Number;
+
+ if(Source != null)
+ this.Source = StringType.FromObject(Source);
+ else
+ this.Source = "";
+
+ if(HelpFile != null)
+ this.HelpFile = StringType.FromObject(HelpFile);
+
+ if(HelpContext != null)
+ this.HelpContext = IntegerType.FromObject(HelpContext);
+
+ if(Description != null)
+ this.Description = StringType.FromObject(Description);
+ else if (DescriptionIsSet == false)
+ this.Description = Utils.GetResourceString(pNumber);
+
+ e = MapNumberToException(pNumber, pDescription);
+
+
+ e.Source = pSource;
+ e.HelpLink = MakeHelpLink(pHelpFile, pHelpContext);
+
+
+ ClearOnCapture = false;
+ throw e;
+ }
+
+ public void SetUnmappedError (int Number)
+ {
+ Clear();
+ this.Number = Number;
+ ClearOnCapture = false;
}
- [MonoTODO]
- public System.Int32 LastDllError {
- get {
- return pLastDllError;
- }
+
+ public System.Exception GetException ()
+ {
+ return pException;
}
- [MonoTODO]
- public System.Int32 Number {
+
+ public System.String Description {
get {
- return pNumber;
+ if(DescriptionIsSet)
+ return pDescription;
+
+ if(pException == null)
+ return "";
+
+ if(pException is Exception)
+ this.Description = FilterDefaultMessage(pException.Message);
+ else
+ this.Description = FilterDefaultMessage(pException.Message);
+
+ return pDescription;
}
set {
- pNumber = value;
+ pDescription = value;
+ DescriptionIsSet = true;
}
}
- [MonoTODO]
+
public System.Int32 Erl {
get {
return pErl;
}
}
- [MonoTODO]
- public System.String Source {
+
+ public System.Int32 HelpContext
+ {
get {
- return pSource;
- }
+ if(HelpContextIsSet)
+ return pHelpContext;
+
+ if(pException != null)
+ {
+ if(pException is Exception)
+ ParseHelpLink(pException.HelpLink);
+ else
+ ParseHelpLink("");
+
+ return this.pHelpContext;
+ }
+ return 0;
+ }
+
set {
- pSource = value;
+ pHelpContext = value;
+ HelpContextIsSet = true;
}
}
- [MonoTODO]
+
public System.String HelpFile {
get {
- return pHelpFile;
+ if (HelpFileIsSet == true)
+ return pHelpFile;
+
+ if(pException != null) {
+ if(pException is Exception)
+ ParseHelpLink((pException as Exception).HelpLink);
+ else
+ ParseHelpLink("");
+
+ return pHelpFile;
+ }
+ return "";
}
set {
pHelpFile = value;
+ HelpFileIsSet = true;
}
}
+
[MonoTODO]
- public System.String Description {
+ public System.Int32 LastDllError {
get {
- return pDescription;
+ return 0;
+ }
+ }
+
+ public System.Int32 Number {
+ get {
+ if(NumberIsSet)
+ return pNumber;
+
+ if(pException == null)
+ return 0;
+
+ this.Number = MapExceptionToNumber(pException);
+ return pNumber;
}
set {
- pDescription = value;
+ pNumber = MapErrorNumber(value);
+ NumberIsSet = true;
}
}
- // Methods
- [MonoTODO("We should parse the exception object to obtain VB-like error code. Not a trivial task!")]
- internal void SetException (Exception ex)
- {
- if (pException != ex) \r
- {
- pNumber = 0xFFFF;
- pSource = ex.Source;
- pDescription = ex.Message + "\n" + ex.StackTrace;
- }
- }
[MonoTODO]
- public System.Exception GetException ()
- {
- return pException;
- }
- [MonoTODO]
- public void Clear () {
- pHelpContext=0;
- pLastDllError=0;
- pNumber=0;
- pErl=0;
- pSource="";
- pHelpFile="";
- pDescription="";
- pException= null;
- }
- [MonoTODO]
- public void Raise (System.Int32 Number, [System.Runtime.InteropServices.Optional] [System.ComponentModel.DefaultValue(null)] System.Object Source, [System.Runtime.InteropServices.Optional] [System.ComponentModel.DefaultValue(null)] System.Object Description, [System.Runtime.InteropServices.Optional] [System.ComponentModel.DefaultValue(null)] System.Object HelpFile, [System.Runtime.InteropServices.Optional] [System.ComponentModel.DefaultValue(null)] System.Object HelpContext)
- {
- throw new NotImplementedException ();
+ public System.String Source {
+ get {
+ if(SourceIsSet)
+ return pSource;
+
+ if(pException == null)
+ return "";
+
+ if(pException is Exception)
+ this.Source = pException.Source;
+ else
+ this.Source = "";
+
+ return pSource;
+ }
+ set {
+ pSource = value;
+ SourceIsSet = true;
+ }
}
- // Events
- };
-}
\ No newline at end of file
+
+
+ }
+}
+
namespace Microsoft.VisualBasic.CompilerServices
{
- /// <summary>
- /// FIXME: Summary description for ProjectData.
- /// </summary>
-
+
[MonoTODO]
[EditorBrowsable(EditorBrowsableState.Never)]
[StructLayout(LayoutKind.Auto)]
- public class ProjectData{
+ public class ProjectData {
- internal static System.Exception projectError;
internal static int erl;
- internal static Microsoft.VisualBasic.ErrObject pErr;
+ internal static Microsoft.VisualBasic.ErrObject pErr = new ErrObject();
- internal static Microsoft.VisualBasic.ErrObject Err
+ internal static System.Exception projectError;
+
+
+ public static void ClearProjectError ()
{
- get
- {
- if (pErr==null)
- pErr=new ErrObject();
+ pErr.Clear();
+ }
+ internal static Microsoft.VisualBasic.ErrObject Err
+ {
+ get {
return pErr;
}
- set
- {
- pErr = value;
- }
}
- /// <summary>
- /// FIXME: Summary description for ClearProjectError
- /// </summary>
- public static void ClearProjectError()
+ public static Exception CreateProjectError(int hr)
{
- projectError = null;
- erl = 0;
+ pErr.Clear();
+ return pErr.CreateException(hr, VBUtils.GetResourceString(pErr.MapErrorNumber(hr)));
}
- /// <summary>
- /// FIXME: Summary description for SetProjectError
- /// </summary>
- /// <param name="ex">FIXME: Required. Summary description for ex</param>
- [MonoTODO]
- public static void SetProjectError(System.Exception ex)
+ public static void SetProjectError(Exception ex)
{
- SetProjectError(ex, 0);
+ pErr.CaptureException(ex);
}
- /// <summary>
- /// FIXME: Summary description for SetProjectError
- /// </summary>
- /// <param name="ex">FIXME: Required. Summary description for ex</param>
- /// <param name="lErl">FIXME: Required. Summary description for lErl</param>
- [MonoTODO]
- public static void SetProjectError(System.Exception ex, int lErl)
+ public static void SetProjectError(Exception ex, int lErl)
{
- projectError = ex;
- erl = lErl;
- Err.SetException (ex);
+ pErr.CaptureException(ex, lErl);
}
+
+
/*
[MonoTODO]
return str;
}
- // public static string GetResourceString(string key, string paramValue)
- // {
- // StringBuilder sb = new StringBuilder(GetResourceString(key));
- // sb.Replace("|1", paramValue);
- // return sb.toString();
- // }
+ public static string GetResourceString (string key, string paramValue)
+ {
+ StringBuilder sb = new StringBuilder(GetResourceString(key));
+ sb.Replace("|1", paramValue);
+ return sb.ToString();
+ }
- // public static string GetResourceString( string key,
- // string paramValue1,
- // string paramValue2)
- // {
- // StringBuilder sb = new StringBuilder(GetResourceString(key));
- // sb.Replace("|1", paramValue1);
- // sb.Replace("|2", paramValue2);
- // return sb.toString();
- // }
+ public static string GetResourceString (string key, string paramValue1, string paramValue2)
+ {
+ StringBuilder sb = new StringBuilder(GetResourceString(key));
+ sb.Replace("|1", paramValue1);
+ sb.Replace("|2", paramValue2);
+ return sb.ToString();
+ }
- // public static string GetResourceString(
- // string key,
- // string param1,
- // string param2,
- // string param3)
- // {
- // StringBuilder sb = new StringBuilder(GetResourceString(key));
- // sb.Replace("|1", param1);
- // sb.Replace("|2", param2);
- // sb.Replace("|3", param3);
- // return sb.toString();
- // }
+ public static string GetResourceString (string key, string param1, string param2, string param3)
+ {
+ StringBuilder sb = new StringBuilder(GetResourceString(key));
+ sb.Replace("|1", param1);
+ sb.Replace("|2", param2);
+ sb.Replace("|3", param3);
+ return sb.ToString();
+ }
- // public static string GetResourceString(
- // string key,
- // string param1,
- // string param2,
- // string param3,
- // string param4)
- // {
- // StringBuilder sb = new StringBuilder(GetResourceString(key));
- // sb.Replace("|1", param1);
- // sb.Replace("|2", param2);
- // sb.Replace("|3", param3);
- // sb.Replace("|4", param4);
- // return sb.toString();
- // }
+ public static string GetResourceString (string key, string param1, string param2, string param3, string param4)
+ {
+ StringBuilder sb = new StringBuilder(GetResourceString(key));
+ sb.Replace("|1", param1);
+ sb.Replace("|2", param2);
+ sb.Replace("|3", param3);
+ sb.Replace("|4", param4);
+ return sb.ToString();
+ }
public static string GetResourceString(int ResourceId)
{
return GetResourceString(str);
}
- // public static string GetResourceString(int ResourceId, string param1)
- // {
- // string str = "ID" + new Integer(ResourceId).toString();
- // return GetResourceString(str, param1);
- // }
+ public static string GetResourceString(int ResourceId, string param1)
+ {
+ string str = "ID" + ResourceId.ToString();
+ return GetResourceString(str, param1);
+ }
// public static java.lang.Exception VBException(java.lang.Exception ex, int hr)
// {