internal static ActiveScriptException Create(IActiveScriptError error)
{
string message = string.Empty;
int errorCode = 0;
short errorWCode = 0;
uint sourceContext = 0;
string subcategory = string.Empty;
string helpLink = string.Empty;
uint lineNumber = 0;
int columnNumber = 0;
string sourceError = string.Empty;
try
{
error.GetSourceLineText(out sourceError);
}
catch
{
// Do nothing
}
try
{
error.GetSourcePosition(out sourceContext, out lineNumber, out columnNumber);
++lineNumber;
++columnNumber;
}
catch
{
// Do nothing
}
try
{
EXCEPINFO excepInfo;
error.GetExceptionInfo(out excepInfo);
message = excepInfo.bstrDescription;
subcategory = excepInfo.bstrSource;
errorCode = excepInfo.scode;
errorWCode = excepInfo.wCode;
if (!string.IsNullOrWhiteSpace(excepInfo.bstrHelpFile)
&& excepInfo.dwHelpContext != 0)
{
helpLink = string.Format("{0}: {1}", excepInfo.bstrHelpFile, excepInfo.dwHelpContext);
}
else if (!string.IsNullOrWhiteSpace(excepInfo.bstrHelpFile))
{
helpLink = excepInfo.bstrHelpFile;
}
}
catch
{
// Do nothing
}
var activeScriptException = new ActiveScriptException(message)
{
ErrorCode = errorCode,
ErrorWCode = errorWCode,
SourceContext = sourceContext,
Subcategory = subcategory,
LineNumber = lineNumber,
ColumnNumber = columnNumber,
SourceError = sourceError,
HelpLink = helpLink,
};
return activeScriptException;
}