Пример #1
0
        /// <summary>
        /// Stores the exception to be returned from
        /// PipelineProcessor.SynchronousExecute, and writes it to
        /// the error variable.
        /// </summary>
        /// <param name="e">
        /// The exception which occurred during script execution
        /// </param>
        /// <exception cref="PipelineStoppedException">
        /// ManageScriptException throws PipelineStoppedException if-and-only-if
        /// the exception is a RuntimeException, otherwise it returns.
        /// This allows the caller to rethrow unexpected exceptions.
        /// </exception>
        internal void ManageScriptException(RuntimeException e)
        {
            if (Command != null && commandRuntime.PipelineProcessor != null)
            {
                commandRuntime.PipelineProcessor.RecordFailure(e, Command);

                // An explicit throw is written to $error as an ErrorRecord, so we
                // skip adding what is more or less a duplicate.
                if (!(e is PipelineStoppedException) && !e.WasThrownFromThrowStatement)
                {
                    commandRuntime.AppendErrorToVariables(e);
                }
            }
            // Upstream cmdlets see only that execution stopped
            throw new PipelineStoppedException();
        }