Ejemplo n.º 1
0
        /// <summary>
        /// Converts the DLR SyntaxErrorException into a Python new-style SyntaxError instance.
        /// </summary>
        private static BaseException /*!*/ SyntaxErrorToPython(SyntaxErrorException /*!*/ e)
        {
            PythonExceptions._SyntaxError se;
            if (e.GetType() == typeof(IndentationException))
            {
                se = new _SyntaxError(IndentationError);
            }
            else if (e.GetType() == typeof(TabException))
            {
                se = new _SyntaxError(TabError);
            }
            else
            {
                se = new _SyntaxError();
            }

            string sourceLine = PythonContext.GetSourceLine(e);
            string fileName   = e.GetSymbolDocumentName();
            object column     = (e.Column == 0 || e.Data[PythonContext._syntaxErrorNoCaret] != null) ? null : (object)e.Column;

            se.args = PythonTuple.MakeTuple(e.Message, PythonTuple.MakeTuple(fileName, e.Line, column, sourceLine));

            se.filename = fileName;
            se.lineno   = e.Line;
            se.offset   = column;
            se.text     = sourceLine;
            se.msg      = e.Message;

            e.SetPythonException(se);

            return(se);
        }
Ejemplo n.º 2
0
            public DynamicExceptionInfo(Exception e)
            {
                ContractUtils.RequiresNotNull(e, "e");

                _exception          = e;
                _dynamicStackFrames = ScriptingRuntimeHelpers.GetDynamicStackFrames(e);

                // We can get the file name and line number from either the
                // DynamicStackFrame or from a SyntaxErrorException
                SyntaxErrorException se = e as SyntaxErrorException;

                if (null != se)
                {
                    _sourceFileName = se.GetSymbolDocumentName();
                    _sourceLine     = se.Line;
                }
                else if (_dynamicStackFrames != null && _dynamicStackFrames.Length > 0)
                {
                    _sourceFileName = _dynamicStackFrames[0].GetFileName();
                    _sourceLine     = _dynamicStackFrames[0].GetFileLineNumber();
                }

                // Try to get the ScriptEngine from the source file's extension;
                // if that fails just use the current ScriptEngine
                ScriptEngine engine = null;

                try {
                    if (_sourceFileName != null)
                    {
                        var extension = System.IO.Path.GetExtension(_sourceFileName);
                        _runtime.TryGetEngineByFileExtension(extension, out engine);
                    }
                    else
                    {
                        throw new Exception();
                    }
                } catch {
                    if (DynamicApplication.Current.Engine != null)
                    {
                        engine = DynamicApplication.Current.Engine.Engine;
                    }
                }

                // If we have the file name and the engine, use ExceptionOperations
                // to generate the exception message. Otherwise, create it by hand
                if (_sourceFileName != null && engine != null)
                {
                    ExceptionOperations es = engine.GetService <ExceptionOperations>();
                    es.GetExceptionMessage(_exception, out _message, out _errorTypeName);
                }
                else
                {
                    _errorTypeName = _exception.GetType().Name;
                    _message       = _errorTypeName + ": " + _exception.Message;
                }
            }
Ejemplo n.º 3
0
            public DynamicExceptionInfo(Exception e)
            {
                ContractUtils.RequiresNotNull(e, "e");

                _exception = e;
                if (DynamicApplication.Current != null && DynamicApplication.Current.Engine != null && DynamicApplication.Current.Engine.Engine != null)
                {
                    _dynamicStackFrames = ArrayUtils.ToArray(DynamicApplication.Current.Engine.Engine.GetService <ExceptionOperations>().GetStackFrames(e));
                }

                // We can get the file name and line number from either the
                // DynamicStackFrame or from a SyntaxErrorException
                SyntaxErrorException se = e as SyntaxErrorException;

                if (null != se)
                {
                    _sourceFileName = se.GetSymbolDocumentName();
                    _sourceLine     = se.Line;
                }
                else if (_dynamicStackFrames != null && _dynamicStackFrames.Length > 0)
                {
                    _sourceFileName = _dynamicStackFrames[0].GetFileName();
                    _sourceLine     = _dynamicStackFrames[0].GetFileLineNumber();
                }

                // Try to get the ScriptEngine from the source file's extension;
                // if that fails just use the current ScriptEngine
                ScriptEngine engine = null;

                try {
                    if (_sourceFileName != null)
                    {
                        var extension = System.IO.Path.GetExtension(_sourceFileName);
                        _runtime.TryGetEngineByFileExtension(extension, out engine);
                    }
                    else
                    {
                        throw new Exception();
                    }
                } catch {
                    if (DynamicApplication.Current.Engine != null)
                    {
                        engine = DynamicApplication.Current.Engine.Engine;
                    }
                }

                // If we have the file name and the engine, use ExceptionOperations
                // to generate the exception message.
                if (_sourceFileName != null && engine != null)
                {
                    ExceptionOperations es = engine.GetService <ExceptionOperations>();
                    es.GetExceptionMessage(_exception, out _message, out _errorTypeName);

                    // Special case error message for needing to upgrade to SL4
                }
                else if (_exception.Message.Contains("Method not found: 'Void System.Threading.Monitor.Enter(System.Object, Boolean ByRef)'"))
                {
                    _errorTypeName = "Silverlight 4 required";
                    _message       = "Silverlight version error: this Silverlight application requires Silverlight 4 to run, please upgrade.";

                    // Otherwise, create it by hand
                }
                else
                {
                    _errorTypeName = _exception.GetType().Name;
                    _message       = _errorTypeName + ": " + _exception.Message;
                }
            }