Inheritance: System.Exception
Ejemplo n.º 1
0
        /// <summary>
        /// Generates a detailed error message
        /// </summary>
        /// <param name="activeScriptException">Active script exception</param>
        /// <returns>Detailed error message</returns>
        public static string Format(ActiveScriptException activeScriptException)
        {
            var errorMessage = new StringBuilder();

            errorMessage.AppendFormatLine("{0}: {1}", Strings.ErrorDetails_Message,
                                          activeScriptException.Message);
            errorMessage.AppendFormatLine("{0}: {1}", Strings.ErrorDetails_ErrorCode,
                                          activeScriptException.ErrorCode);
            if (activeScriptException.ErrorWCode != 0)
            {
                errorMessage.AppendFormatLine("{0}: {1}", Strings.ErrorDetails_ErrorWCode,
                                              activeScriptException.ErrorWCode);
            }
            errorMessage.AppendFormatLine("{0}: {1}", Strings.ErrorDetails_Subcategory,
                                          activeScriptException.Subcategory);
            if (!string.IsNullOrWhiteSpace(activeScriptException.HelpLink))
            {
                errorMessage.AppendFormatLine("{0}: {1}", Strings.ErrorDetails_HelpKeyword,
                                              activeScriptException.HelpLink);
            }
            errorMessage.AppendFormatLine("{0}: {1}", Strings.ErrorDetails_LineNumber,
                                          activeScriptException.LineNumber.ToString());
            if (!string.IsNullOrWhiteSpace(activeScriptException.SourceError))
            {
                errorMessage.AppendFormatLine("{0}: {1}", Strings.ErrorDetails_LineSource,
                                              activeScriptException.SourceError);
            }

            return(errorMessage.ToString());
        }
        /// <summary>
        /// Destroys object
        /// </summary>
        /// <param name="disposing">Flag, allowing destruction of
        /// managed objects contained in fields of class</param>
        private void Dispose(bool disposing)
        {
            if (!_disposed)
            {
                _disposed = true;

                _lastException = null;

                if (_siteItems != null)
                {
                    _siteItems.Clear();
                    _siteItems = null;
                }

                if (_dispatch != null)
                {
                    ComHelpers.ReleaseComObject(ref _dispatch, !disposing);
                    _dispatch = null;
                }

                if (_activeScriptParse != null)
                {
                    _activeScriptParse.Dispose();
                    _activeScriptParse = null;
                }

                _activeScript = null;
            }
        }
        /// <summary>
        /// Generates a detailed error message
        /// </summary>
        /// <param name="activeScriptException">Active script exception</param>
        /// <returns>Detailed error message</returns>
        public static string Format(ActiveScriptException activeScriptException)
        {
            var errorMessage = new StringBuilder();
            errorMessage.AppendFormatLine("{0}: {1}", Strings.ErrorDetails_Message,
                activeScriptException.Message);
            errorMessage.AppendFormatLine("{0}: {1}", Strings.ErrorDetails_ErrorCode,
                activeScriptException.ErrorCode);
            if (activeScriptException.ErrorWCode != 0)
            {
                errorMessage.AppendFormatLine("{0}: {1}", Strings.ErrorDetails_ErrorWCode,
                    activeScriptException.ErrorWCode);
            }
            errorMessage.AppendFormatLine("{0}: {1}", Strings.ErrorDetails_Subcategory,
                activeScriptException.Subcategory);
            if (!string.IsNullOrWhiteSpace(activeScriptException.HelpLink))
            {
                errorMessage.AppendFormatLine("{0}: {1}", Strings.ErrorDetails_HelpKeyword,
                    activeScriptException.HelpLink);
            }
            errorMessage.AppendFormatLine("{0}: {1}", Strings.ErrorDetails_LineNumber,
                activeScriptException.LineNumber.ToString());
            if (!string.IsNullOrWhiteSpace(activeScriptException.SourceError))
            {
                errorMessage.AppendFormatLine("{0}: {1}", Strings.ErrorDetails_LineSource,
                    activeScriptException.SourceError);
            }

            return errorMessage.ToString();
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Gets and resets a last exception. Returns null for none.
        /// </summary>
        private ActiveScriptException GetAndResetLastException()
        {
            ActiveScriptException temp = _lastException;

            _lastException = null;

            return(temp);
        }
Ejemplo n.º 5
0
        private void ThrowError()
        {
            ActiveScriptException last = GetAndResetLastException();

            if (last != null)
            {
                throw last;
            }
        }
            public void OnScriptErrorDebug(IActiveScriptErrorDebug errorDebug, out bool enterDebugger,
                                           out bool callOnScriptErrorWhenContinuing)
            {
                var error = errorDebug as IActiveScriptError;

                if (error != null)
                {
                    _jsEngine._lastException = ActiveScriptException.Create(GetErrorDetails(error), error);
                }

                enterDebugger = true;
                callOnScriptErrorWhenContinuing = true;
            }
Ejemplo n.º 7
0
        private JsRuntimeException ConvertActiveScriptExceptionToJsRuntimeException(
            ActiveScriptException activeScriptException)
        {
            var jsEngineException = new JsRuntimeException(activeScriptException.Message, _engineModeName)
            {
                ErrorCode      = activeScriptException.ErrorCode.ToString(CultureInfo.InvariantCulture),
                Category       = activeScriptException.Subcategory,
                LineNumber     = (int)activeScriptException.LineNumber,
                ColumnNumber   = activeScriptException.ColumnNumber,
                SourceFragment = activeScriptException.SourceError,
                HelpLink       = activeScriptException.HelpLink
            };

            return(jsEngineException);
        }
        /// <summary>
        /// Destroys object
        /// </summary>
        /// <param name="disposing">Flag, allowing destruction of
        /// managed objects contained in fields of class</param>
        private void Dispose(bool disposing)
        {
            if (_disposedFlag.Set())
            {
                _dispatcher.Invoke(() =>
                {
                    if (_dispatch != null)
                    {
                        ComHelpers.ReleaseComObject(ref _dispatch, !disposing);
                        _dispatch = null;
                    }

                    if (_activeScriptWrapper != null)
                    {
                        _activeScriptWrapper.Dispose();
                        _activeScriptWrapper = null;
                    }
                });

                if (disposing)
                {
                    if (_debuggingStarted && _debugDocuments != null)
                    {
                        foreach (UIntPtr debugDocumentKey in _debugDocuments.Keys)
                        {
                            var debugDocumentValue = _debugDocuments[debugDocumentKey];
                            debugDocumentValue.Close();
                        }

                        _debugDocuments.Clear();
                    }

                    if (_processDebugManagerWrapper != null)
                    {
                        _processDebugManagerWrapper.RemoveApplication(_debugApplicationCookie);
                        _debugApplicationWrapper.Close();
                    }

                    if (_hostItems != null)
                    {
                        _hostItems.Clear();
                    }

                    _lastException = null;
                }
            }
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Destroys object
        /// </summary>
        /// <param name="disposing">Flag, allowing destruction of
        /// managed objects contained in fields of class</param>
        private void Dispose(bool disposing)
        {
            if (_disposedFlag.Set())
            {
                _dispatcher.Invoke(() =>
                {
                    if (_dispatch != null)
                    {
                        ComHelpers.ReleaseComObject(ref _dispatch, !disposing);
                        _dispatch = null;
                    }

                    _activeScriptGarbageCollector = null;
                    ComHelpers.ReleaseAndEmpty(ref _pActiveScriptGarbageCollector);

                    if (_activeScriptParse != null)
                    {
                        _activeScriptParse.Dispose();
                        _activeScriptParse = null;
                    }

                    if (_activeScript != null)
                    {
                        _activeScript.Close();
                        Marshal.FinalReleaseComObject(_activeScript);
                        _activeScript = null;
                    }

                    ComHelpers.ReleaseAndEmpty(ref _pActiveScript);
                });

                if (disposing)
                {
                    if (_hostItems != null)
                    {
                        _hostItems.Clear();
                    }

                    _lastException = null;
                }
            }
        }
Ejemplo n.º 10
0
 /// <summary>
 /// Informs the host that an execution error occurred while the engine was running the script
 /// </summary>
 /// <param name="exception">The exception</param>
 protected virtual void OnScriptError(ActiveScriptException exception)
 {
 }
 public void OnScriptError(IActiveScriptError error)
 {
     _jsEngine._lastException = ActiveScriptException.Create(GetErrorDetails(error), error);
 }
Ejemplo n.º 12
0
        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;
        }
        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);
        }
Ejemplo n.º 14
0
 /// <summary>
 /// Informs the host that an execution error occurred while the engine was running the script.
 /// </summary>
 /// <param name="scriptError">A host can use this interface to obtain information about the
 /// execution error</param>
 void IActiveScriptSite.OnScriptError(IActiveScriptError scriptError)
 {
     _lastException = ActiveScriptException.Create(scriptError);
 }
 /// <summary>
 /// Informs the host that an execution error occurred while the engine was running the script.
 /// </summary>
 /// <param name="scriptError">A host can use this interface to obtain information about the
 /// execution error</param>
 public void OnScriptError(IActiveScriptError scriptError)
 {
     _lastException = ActiveScriptException.Create(scriptError);
     OnScriptError(_lastException);
 }
 /// <summary>
 /// Informs the host that an execution error occurred while the engine was running the script
 /// </summary>
 /// <param name="exception">The exception</param>
 protected virtual void OnScriptError(ActiveScriptException exception)
 {
 }
        /// <summary>
        /// Destroys object
        /// </summary>
        /// <param name="disposing">Flag, allowing destruction of
        /// managed objects contained in fields of class</param>
        private void Dispose(bool disposing)
        {
            if (!_disposed)
            {
                _disposed = true;

                _lastException = null;

                if (_siteItems != null)
                {
                    _siteItems.Clear();
                    _siteItems = null;
                }

                if (_dispatch != null)
                {
                    ComHelpers.ReleaseComObject(ref _dispatch, !disposing);
                    _dispatch = null;
                }

                if (_activeScriptParse != null)
                {
                    _activeScriptParse.Dispose();
                    _activeScriptParse = null;
                }

                _activeScript = null;
            }
        }
        /// <summary>
        /// Gets and resets a last exception. Returns null for none.
        /// </summary>
        private ActiveScriptException GetAndResetLastException()
        {
            var temp = _lastException;
            _lastException = null;

            return temp;
        }
Ejemplo n.º 19
0
 /// <summary>
 /// Informs the host that an execution error occurred while the engine was running the script.
 /// </summary>
 /// <param name="scriptError">A host can use this interface to obtain information about the
 /// execution error</param>
 public void OnScriptError(IActiveScriptError scriptError)
 {
     _lastException = ActiveScriptException.Create(scriptError);
     OnScriptError(_lastException);
 }