Пример #1
0
        internal static RuntimeException ConvertToException(object result, IScriptExtent extent)
        {
            result = PSObject.Base(result);
            RuntimeException exception = result as RuntimeException;

            if (exception != null)
            {
                InterpreterError.UpdateExceptionErrorRecordPosition(exception, extent);
                exception.WasThrownFromThrowStatement = true;
                return(exception);
            }
            ErrorRecord errorRecord = result as ErrorRecord;

            if (errorRecord != null)
            {
                exception = new RuntimeException(errorRecord.ToString(), errorRecord.Exception, errorRecord)
                {
                    WasThrownFromThrowStatement = true
                };
                InterpreterError.UpdateExceptionErrorRecordPosition(exception, extent);
                return(exception);
            }
            Exception exception3 = result as Exception;

            if (exception3 != null)
            {
                errorRecord = new ErrorRecord(exception3, exception3.Message, ErrorCategory.OperationStopped, null);
                exception   = new RuntimeException(exception3.Message, exception3, errorRecord)
                {
                    WasThrownFromThrowStatement = true
                };
                InterpreterError.UpdateExceptionErrorRecordPosition(exception, extent);
                return(exception);
            }
            string message = LanguagePrimitives.IsNull(result) ? "ScriptHalted" : ParserOps.ConvertTo <string>(result, PositionUtilities.EmptyExtent);

            exception3  = new RuntimeException(message, null);
            errorRecord = new ErrorRecord(exception3, message, ErrorCategory.OperationStopped, null);
            exception   = new RuntimeException(message, exception3, errorRecord)
            {
                WasThrownFromThrowStatement = true
            };
            exception.SetTargetObject(result);
            InterpreterError.UpdateExceptionErrorRecordPosition(exception, extent);
            return(exception);
        }
Пример #2
0
        internal static RuntimeException NewInterpreterExceptionWithInnerException(object targetObject, Type exceptionType, IScriptExtent errorPosition, string resourceIdAndErrorId, string resourceString, Exception innerException, params object[] args)
        {
            if (string.IsNullOrEmpty(resourceIdAndErrorId))
            {
                throw PSTraceSource.NewArgumentException("resourceIdAndErrorId");
            }
            RuntimeException exception = null;

            try
            {
                string str;
                if ((args == null) || (args.Length == 0))
                {
                    str = resourceString;
                }
                else
                {
                    str = StringUtil.Format(resourceString, args);
                }
                if (string.IsNullOrEmpty(str))
                {
                    exception = NewBackupInterpreterException(exceptionType, errorPosition, resourceIdAndErrorId, null);
                }
                else
                {
                    exception = NewInterpreterExceptionByMessage(exceptionType, errorPosition, str, resourceIdAndErrorId, innerException);
                }
            }
            catch (InvalidOperationException exception2)
            {
                exception = NewBackupInterpreterException(exceptionType, errorPosition, resourceIdAndErrorId, exception2);
            }
            catch (MissingManifestResourceException exception3)
            {
                exception = NewBackupInterpreterException(exceptionType, errorPosition, resourceIdAndErrorId, exception3);
            }
            catch (FormatException exception4)
            {
                exception = NewBackupInterpreterException(exceptionType, errorPosition, resourceIdAndErrorId, exception4);
            }
            exception.SetTargetObject(targetObject);
            return(exception);
        }
Пример #3
0
        private RuntimeException ConvertToException(
            object result,
            ExecutionContext context)
        {
            result = PSObject.Base(result);
            if (LanguagePrimitives.IsNull(result) && context.CurrentExceptionBeingHandled != null && this._inCatch)
            {
                result = (object)context.CurrentExceptionBeingHandled;
            }
            switch (result)
            {
            case RuntimeException runtimeException3:
                runtimeException3.WasThrownFromThrowStatement = true;
                return(runtimeException3);

            case ErrorRecord errorRecord3:
                RuntimeException runtimeException1 = new RuntimeException(errorRecord3.ToString(), errorRecord3.Exception, errorRecord3);
                if (errorRecord3.InvocationInfo == null)
                {
                    errorRecord3.SetInvocationInfo(new InvocationInfo((CommandInfo)null, this.NodeToken, context));
                }
                runtimeException1.WasThrownFromThrowStatement = true;
                return(runtimeException1);

            case Exception exception2:
                ErrorRecord errorRecord1 = new ErrorRecord(exception2, exception2.Message, ErrorCategory.OperationStopped, (object)null);
                errorRecord1.SetInvocationInfo(new InvocationInfo((CommandInfo)null, this.NodeToken, context));
                return(new RuntimeException(exception2.Message, exception2, errorRecord1)
                {
                    WasThrownFromThrowStatement = true
                });

            default:
                string      str          = LanguagePrimitives.IsNull(result) ? "ScriptHalted" : Parser.ConvertTo <string>(result, this.NodeToken);
                Exception   exception1   = (Exception) new RuntimeException(str, (Exception)null);
                ErrorRecord errorRecord2 = new ErrorRecord(exception1, str, ErrorCategory.OperationStopped, (object)null);
                errorRecord2.SetInvocationInfo(new InvocationInfo((CommandInfo)null, this.NodeToken, context));
                RuntimeException runtimeException2 = new RuntimeException(str, exception1, errorRecord2);
                runtimeException2.WasThrownFromThrowStatement = true;
                runtimeException2.SetTargetObject(result);
                return(runtimeException2);
            }
        }
Пример #4
0
 internal static RuntimeException ConvertToException(object result, IScriptExtent extent)
 {
     result = PSObject.Base(result);
     RuntimeException exception = result as RuntimeException;
     if (exception != null)
     {
         InterpreterError.UpdateExceptionErrorRecordPosition(exception, extent);
         exception.WasThrownFromThrowStatement = true;
         return exception;
     }
     ErrorRecord errorRecord = result as ErrorRecord;
     if (errorRecord != null)
     {
         exception = new RuntimeException(errorRecord.ToString(), errorRecord.Exception, errorRecord) {
             WasThrownFromThrowStatement = true
         };
         InterpreterError.UpdateExceptionErrorRecordPosition(exception, extent);
         return exception;
     }
     Exception exception3 = result as Exception;
     if (exception3 != null)
     {
         errorRecord = new ErrorRecord(exception3, exception3.Message, ErrorCategory.OperationStopped, null);
         exception = new RuntimeException(exception3.Message, exception3, errorRecord) {
             WasThrownFromThrowStatement = true
         };
         InterpreterError.UpdateExceptionErrorRecordPosition(exception, extent);
         return exception;
     }
     string message = LanguagePrimitives.IsNull(result) ? "ScriptHalted" : ParserOps.ConvertTo<string>(result, PositionUtilities.EmptyExtent);
     exception3 = new RuntimeException(message, null);
     errorRecord = new ErrorRecord(exception3, message, ErrorCategory.OperationStopped, null);
     exception = new RuntimeException(message, exception3, errorRecord) {
         WasThrownFromThrowStatement = true
     };
     exception.SetTargetObject(result);
     InterpreterError.UpdateExceptionErrorRecordPosition(exception, extent);
     return exception;
 }