Beispiel #1
0
        public static void Eval(AphidInterpreter interpreter, string code, bool isTextDocument)
        {
            if (AphidErrorHandling.HandleErrors)
            {
                var backup = false;

                try
                {
                    backup = interpreter.SetIsInTryCatchFinally(true);

#if APHID_FRAME_ADD_DATA || APHID_FRAME_CATCH_POP
                    try
                    {
#endif
                    interpreter.Interpret(code, isTextDocument);
#if APHID_FRAME_ADD_DATA || APHID_FRAME_CATCH_POP
                }
#endif
#if APHID_FRAME_ADD_DATA || APHID_FRAME_CATCH_POP
#if APHID_FRAME_ADD_DATA
                    catch (Exception e)
#else
                    catch
#endif
                    {
                        if (e.Source != AphidName.DebugInterpreter)
                        {
                            e.Source = AphidName.DebugInterpreter;

#if APHID_FRAME_CATCH_POP
                            interpreter.PopQueuedFrames();
#endif

#if APHID_FRAME_ADD_DATA
                            e.Data.Add(AphidName.Interpreter, interpreter);
                            e.Data.Add(AphidName.FramesKey, interpreter.GetRawStackTrace());
#endif
                        }

                        throw;
                    }
#endif
                }
                catch (ThreadAbortException exception)
                {
                    if (!IsAborting)
                    {
                        Thread.ResetAbort();
                        DumpException(exception, interpreter);
                        Exit((int)GeneralError);
                    }
                }
                catch (AphidParserException exception)
                {
                    DumpException(exception, code);
                    Exit((int)ParserError);
                }
                catch (AphidLoadScriptException exception)
                {
                    DumpException(exception, interpreter);
                    Exit((int)LoadScriptError);
                }
                catch (AphidRuntimeException exception)
                {
                    DumpException(exception, interpreter);
                    Exit((int)RuntimeError);
                }
                catch (Exception exception)
                {
                    DumpException(exception, interpreter);
                    Exit((int)GeneralError);
                }
                finally
                {
                    interpreter.SetIsInTryCatchFinally(backup);
                }
            }
            else
            {
                interpreter.Interpret(code, isTextDocument);
            }
        }
Beispiel #2
0
 public static void DumpStackTrace(AphidInterpreter interpreter) =>
 DumpStackTrace(interpreter, interpreter.GetRawStackTrace());
Beispiel #3
0
        private static bool TryActionCore(
            AphidInterpreter interpreter,
            Func <string> getCode,
            Action action,
            bool allowErrorReporting)
        {
            var backup = false;

            try
            {
                backup = interpreter.SetIsInTryCatchFinally(true);
#if APHID_FRAME_ADD_DATA || APHID_FRAME_CATCH_POP
                try
                {
#endif
                action();
#if APHID_FRAME_ADD_DATA || APHID_FRAME_CATCH_POP
            }
#endif
#if APHID_FRAME_ADD_DATA || APHID_FRAME_CATCH_POP
#if APHID_FRAME_ADD_DATA
                catch (Exception e)
#else
                catch
#endif
                {
                    if (e.Source != AphidName.DebugInterpreter)
                    {
                        e.Source = AphidName.DebugInterpreter;

#if APHID_FRAME_CATCH_POP
                        interpreter.PopQueuedFrames(1);
#endif

#if APHID_FRAME_ADD_DATA
                        e.Data.Add(AphidName.Interpreter, interpreter);
                        e.Data.Add(AphidName.FramesKey, interpreter.GetRawStackTrace());
#endif
                    }

                    throw;
                }
#endif
                interpreter.SetIsInTryCatchFinally(backup);

                return(true);
            }
            catch (ThreadAbortException exception)
            {
                if (!IsAborting)
                {
                    Thread.ResetAbort();
                    LastException = exception;
                    DumpException(exception, interpreter);
                }
            }
            catch (AphidParserException exception)
            {
                LastException = exception;
                DumpException(exception, getCode());
            }
            catch (AphidLoadScriptException exception)
            {
                LastException = exception;
                DumpException(exception, interpreter);
            }
            catch (AphidRuntimeException exception)
            {
                LastException = exception;
                DumpException(exception, interpreter);
            }
            catch (TargetInvocationException exception)
                when(exception.InnerException is AphidParserException parserException)
                {
                    LastException = parserException;
                    DumpException(parserException, getCode());
                }
            catch (TargetInvocationException exception)
                when(exception.InnerException is AphidLoadScriptException loadScriptException)
                {
                    LastException = loadScriptException;
                    DumpException(loadScriptException, interpreter);
                }
            catch (TargetInvocationException exception)
                when(exception.InnerException is AphidRuntimeException runtimeException)
                {
                    LastException = runtimeException;
                    DumpException(runtimeException, interpreter);
                }
            catch (Exception exception)
            {
                LastException = exception;
                DumpException(exception, interpreter);
            }

            if (allowErrorReporting)
            {
                AphidErrorReporter.Report(LastException, interpreter, passThrough: false);
            }

            interpreter.SetIsInTryCatchFinally(backup);

            return(false);
        }
Beispiel #4
0
 public static void DumpStackTrace(AphidInterpreter interpreter, Exception exception) =>
 DumpStackTrace(
     interpreter,
     exception.Data.Contains(AphidName.FramesKey) ?
     (AphidFrame[])exception.Data[AphidName.FramesKey] :
     interpreter.GetRawStackTrace());