Example #1
0
        public object Execute(Program program)
        {
                        #if WRAPRUNTIMEEXCEPTIONS
            try
            {
                        #endif

            if (IsBreakable)
            {
                program.Yield(this, false);
            }
            else
            {
                program.CheckAborted();
            }

            // TODO: Compile this call, the TableNode is the only node that uses this hook
            InternalBeforeExecute(program);
            if (DeviceSupported)
            {
                return(program.DeviceExecute(_device, this));
            }
            return(InternalExecute(program));

                        #if WRAPRUNTIMEEXCEPTIONS
        }

        catch (Exception exception)
        {
            bool      isNew   = false;
            Exception toThrow = null;

            RuntimeException runtimeException = exception as RuntimeException;
            if (runtimeException != null)
            {
                if (!runtimeException.HasContext())
                {
                    runtimeException.SetLocator(program.GetLocation(this, true));
                    isNew = true;
                }
                toThrow = runtimeException;
            }

            if ((toThrow == null) && (exception is ControlError))
            {
                throw exception;
            }

            if ((toThrow == null) && (exception is NullReferenceException))
            {
                toThrow = new RuntimeException(RuntimeException.Codes.NilEncountered, exception, program.GetLocation(this, true));
                isNew   = true;
            }

            if (toThrow == null)
            {
                DataphorException dataphorException = exception as DataphorException;
                if (dataphorException != null)
                {
                    if ((dataphorException.Severity == ErrorSeverity.User) || (dataphorException.ServerContext != null) || (dataphorException.Code == (int)RuntimeException.Codes.RuntimeError))
                    {
                        toThrow = dataphorException;
                    }
                    else
                    {
                        toThrow = new RuntimeException(RuntimeException.Codes.RuntimeError, dataphorException.Severity, dataphorException, program.GetLocation(this, true), dataphorException.Message);
                        isNew   = true;
                    }
                }
            }

            if ((toThrow == null) && ((exception is FormatException) || (exception is ArgumentException) || (exception is ArithmeticException)))
            {
                toThrow = new DataphorException(ErrorSeverity.User, DataphorException.ApplicationError, exception.Message, exception);
                isNew   = true;
            }

            if (toThrow == null)
            {
                toThrow = new RuntimeException(RuntimeException.Codes.RuntimeError, ErrorSeverity.Application, exception, program.GetLocation(this, true), exception.Message);
                isNew   = true;
            }

            if (isNew)
            {
                program.ReportThrow();
            }

            if (IsBreakable)
            {
                program.Yield(this, true);
            }

            throw toThrow;
        }
                        #endif
        }