Team Ai
Datasetpublic

MegaBites-AI/Windows-powershell

sourceHugging Facemitupdated 6mo agoView on Hugging Face
0likes308downloads
ExecutionExceptions.cs978 linesDownload Raw Back to utils
1// Copyright (c) Microsoft Corporation.2// Licensed under the MIT License.3 4#pragma warning disable 1634, 16915#pragma warning disable 565066 7using System.Runtime.Serialization;8using System.Diagnostics.CodeAnalysis;9using System.Management.Automation.Internal;10 11#pragma warning disable 1634, 1691 // Stops compiler from warning about unknown warnings12 13namespace System.Management.Automation14{15    #region CmdletInvocationException16    /// <summary>17    /// Indicates that a cmdlet hit a terminating error.18    /// </summary>19    /// <remarks>20    /// InnerException is the error which the cmdlet hit.21    /// </remarks>22    public class CmdletInvocationException : RuntimeException23    {24        #region ctor25        /// <summary>26        /// Instantiates a new instance of the CmdletInvocationException class.27        /// </summary>28        /// <param name="errorRecord"></param>29        internal CmdletInvocationException(ErrorRecord errorRecord)30            : base(RetrieveMessage(errorRecord), RetrieveException(errorRecord))31        {32            ArgumentNullException.ThrowIfNull(errorRecord);33 34            _errorRecord = errorRecord;35            if (errorRecord.Exception != null)36            {37                // 2005/04/13-JonN Can't do this in an unsealed class: HelpLink = errorRecord.Exception.HelpLink;38                // Exception.Source is set by Throw39                // Source = errorRecord.Exception.Source;40            }41        }42 43        /// <summary>44        /// Instantiates a new instance of the CmdletInvocationException class.45        /// </summary>46        /// <param name="innerException">Wrapped exception.</param>47        /// <param name="invocationInfo">48        /// identity of cmdlet, null is unknown49        /// </param>50        internal CmdletInvocationException(Exception innerException,51                                           InvocationInfo invocationInfo)52            : base(RetrieveMessage(innerException), innerException)53        {54            ArgumentNullException.ThrowIfNull(innerException);55            // invocationInfo may be null56 57            if (innerException is IContainsErrorRecord icer && icer.ErrorRecord != null)58            {59                _errorRecord = new ErrorRecord(icer.ErrorRecord, innerException);60            }61            else62            {63                // When no ErrorId is specified by a thrown exception,64                //  we use innerException.GetType().FullName.65                _errorRecord = new ErrorRecord(66                    innerException,67                    innerException.GetType().FullName,68                    ErrorCategory.NotSpecified,69                    null);70            }71 72            _errorRecord.SetInvocationInfo(invocationInfo);73            // 2005/04/13-JonN Can't do this in an unsealed class: HelpLink = innerException.HelpLink;74            // Exception.Source is set by Throw75            // Source = innerException.Source;76        }77 78        /// <summary>79        /// Instantiates a new instance of the CmdletInvocationException class.80        /// </summary>81        public CmdletInvocationException()82            : base()83        {84        }85 86        /// <summary>87        /// Instantiates a new instance of the CmdletInvocationException class.88        /// </summary>89        /// <param name="message"></param>90        /// <returns>Constructed object.</returns>91        public CmdletInvocationException(string message)92            : base(message)93        {94        }95 96        /// <summary>97        /// Instantiates a new instance of the CmdletInvocationException class.98        /// </summary>99        /// <param name="message"></param>100        /// <param name="innerException"></param>101        /// <returns>Constructed object.</returns>102        public CmdletInvocationException(string message,103                                         Exception innerException)104            : base(message, innerException)105        {106        }107 108        #region Serialization109        /// <summary>110        /// Initializes a new instance of the CmdletInvocationException class111        /// using data serialized via112        /// <see cref="ISerializable"/>113        /// </summary>114        /// <param name="info">Serialization information.</param>115        /// <param name="context">Streaming context.</param>116        /// <returns>Constructed object.</returns>117        [Obsolete("Legacy serialization support is deprecated since .NET 8", DiagnosticId = "SYSLIB0051")]118        protected CmdletInvocationException(SerializationInfo info,119                                            StreamingContext context)120        {121            throw new NotSupportedException();122        }123        #endregion Serialization124        #endregion ctor125 126        #region Properties127        /// <summary>128        /// The error reported by the cmdlet.129        /// </summary>130        /// <value>never null</value>131        public override ErrorRecord ErrorRecord132        {133            get134            {135                _errorRecord ??= new ErrorRecord(136                    new ParentContainsErrorRecordException(this),137                    "CmdletInvocationException",138                    ErrorCategory.NotSpecified,139                    null);140 141                return _errorRecord;142            }143        }144 145        private ErrorRecord _errorRecord = null;146 147        #endregion Properties148    }149    #endregion CmdletInvocationException150 151    #region CmdletProviderInvocationException152    /// <summary>153    /// Indicates that a cmdlet hit a terminating error of type154    /// <see cref="System.Management.Automation.ProviderInvocationException"/>.155    /// This is generally reported from the standard provider navigation cmdlets156    /// such as get-childitem.157    /// </summary>158    public class CmdletProviderInvocationException : CmdletInvocationException159    {160        #region ctor161        /// <summary>162        /// Instantiates a new instance of the CmdletProviderInvocationException class.163        /// </summary>164        /// <param name="innerException">Wrapped exception.</param>165        /// <param name="myInvocation">166        /// identity of cmdlet, null is unknown167        /// </param>168        /// <returns>Constructed object.</returns>169        internal CmdletProviderInvocationException(170                    ProviderInvocationException innerException,171                    InvocationInfo myInvocation)172            : base(GetInnerException(innerException), myInvocation)173        {174            ArgumentNullException.ThrowIfNull(innerException);175 176            _providerInvocationException = innerException;177        }178 179        /// <summary>180        /// Instantiates a new instance of the CmdletProviderInvocationException class.181        /// </summary>182        /// <returns>Constructed object.</returns>183        public CmdletProviderInvocationException()184            : base()185        {186        }187 188        /// <summary>189        /// Initializes a new instance of the CmdletProviderInvocationException class190        /// using data serialized via191        /// <see cref="ISerializable"/>192        /// </summary>193        /// <param name="info">Serialization information.</param>194        /// <param name="context">Streaming context.</param>195        /// <returns>Constructed object.</returns>196        [Obsolete("Legacy serialization support is deprecated since .NET 8", DiagnosticId = "SYSLIB0051")]197        protected CmdletProviderInvocationException(SerializationInfo info,198                                                    StreamingContext context)199        {200            throw new NotSupportedException();201        }202 203        /// <summary>204        /// Instantiates a new instance of the CmdletProviderInvocationException class.205        /// </summary>206        /// <param name="message"></param>207        /// <returns>Constructed object.</returns>208        public CmdletProviderInvocationException(string message)209            : base(message)210        {211        }212 213        /// <summary>214        /// Instantiates a new instance of the CmdletProviderInvocationException class.215        /// </summary>216        /// <param name="message"></param>217        /// <param name="innerException"></param>218        /// <returns>Constructed object.</returns>219        public CmdletProviderInvocationException(string message,220                                                 Exception innerException)221            : base(message, innerException)222        {223            _providerInvocationException = innerException as ProviderInvocationException;224        }225        #endregion ctor226 227        #region Properties228        /// <summary>229        /// InnerException as ProviderInvocationException.230        /// </summary>231        /// <value>ProviderInvocationException</value>232        public ProviderInvocationException ProviderInvocationException233        {234            get235            {236                return _providerInvocationException;237            }238        }239 240        [NonSerialized]241        private readonly ProviderInvocationException _providerInvocationException;242 243        /// <summary>244        /// This is the ProviderInfo associated with the provider which245        /// generated the error.246        /// </summary>247        /// <value>may be null</value>248        public ProviderInfo ProviderInfo249        {250            get251            {252                return _providerInvocationException?.ProviderInfo;253            }254        }255 256        #endregion Properties257 258        #region Internal259        private static Exception GetInnerException(Exception e)260        {261            return e?.InnerException;262        }263        #endregion Internal264    }265    #endregion CmdletProviderInvocationException266 267    #region PipelineStoppedException268    /// <summary>269    /// Indicates that the pipeline has already been stopped.270    /// </summary>271    /// <remarks>272    /// When reported as the result of a command, PipelineStoppedException273    /// indicates that the command was stopped asynchronously, either by the274    /// user hitting CTRL-C, or by a call to275    /// <see cref="System.Management.Automation.Runspaces.Pipeline.Stop"/>.276    ///277    /// When a cmdlet or provider sees this exception thrown from a PowerShell API such as278    ///     WriteObject(object)279    /// this means that the command was already stopped.  The cmdlet or provider280    /// should clean up and return.281    /// Catching this exception is optional; if the cmdlet or providers chooses not to282    /// handle PipelineStoppedException and instead allow it to propagate to the283    /// PowerShell Engine's call to ProcessRecord, the PowerShell Engine will handle it properly.284    /// </remarks>285    public class PipelineStoppedException : RuntimeException286    {287        #region ctor288        /// <summary>289        /// Instantiates a new instance of the PipelineStoppedException class.290        /// </summary>291        /// <returns>Constructed object.</returns>292        public PipelineStoppedException()293            : base(GetErrorText.PipelineStoppedException)294        {295            SetErrorId("PipelineStopped");296            SetErrorCategory(ErrorCategory.OperationStopped);297        }298 299        /// <summary>300        /// Initializes a new instance of the PipelineStoppedException class301        /// using data serialized via302        /// <see cref="ISerializable"/>303        /// </summary>304        /// <param name="info">Serialization information.</param>305        /// <param name="context">Streaming context.</param>306        /// <returns>Constructed object.</returns>307        [Obsolete("Legacy serialization support is deprecated since .NET 8", DiagnosticId = "SYSLIB0051")]308        protected PipelineStoppedException(SerializationInfo info,309                                           StreamingContext context)310        {311            throw new NotSupportedException();312        }313 314        /// <summary>315        /// Instantiates a new instance of the PipelineStoppedException class.316        /// </summary>317        /// <param name="message"></param>318        /// <returns>Constructed object.</returns>319        public PipelineStoppedException(string message)320            : base(message)321        {322        }323 324        /// <summary>325        /// Instantiates a new instance of the PipelineStoppedException class.326        /// </summary>327        /// <param name="message"></param>328        /// <param name="innerException"></param>329        /// <returns>Constructed object.</returns>330        public PipelineStoppedException(string message,331                                        Exception innerException)332            : base(message, innerException)333        {334        }335        #endregion ctor336    }337    #endregion PipelineStoppedException338 339    #region PipelineClosedException340    /// <summary>341    /// PipelineClosedException occurs when someone tries to write342    /// to an asynchronous pipeline source and the pipeline has already343    /// been stopped.344    /// </summary>345    /// <seealso cref="System.Management.Automation.Runspaces.Pipeline.Input"/>346    public class PipelineClosedException : RuntimeException347    {348        #region ctor349        /// <summary>350        /// Instantiates a new instance of the PipelineClosedException class.351        /// </summary>352        /// <returns>Constructed object.</returns>353        public PipelineClosedException()354            : base()355        {356        }357 358        /// <summary>359        /// Instantiates a new instance of the PipelineClosedException class.360        /// </summary>361        /// <param name="message"></param>362        /// <returns>Constructed object.</returns>363        public PipelineClosedException(string message)364            : base(message)365        {366        }367 368        /// <summary>369        /// Instantiates a new instance of the PipelineClosedException class.370        /// </summary>371        /// <param name="message"></param>372        /// <param name="innerException"></param>373        /// <returns>Constructed object.</returns>374        public PipelineClosedException(string message,375                                       Exception innerException)376            : base(message, innerException)377        {378        }379        #endregion ctor380 381        #region Serialization382        /// <summary>383        /// Initializes a new instance of the PipelineClosedException class384        /// using data serialized via385        /// <see cref="ISerializable"/>386        /// </summary>387        /// <param name="info">Serialization information.</param>388        /// <param name="context">Streaming context.</param>389        /// <returns>Constructed object.</returns>390        [Obsolete("Legacy serialization support is deprecated since .NET 8", DiagnosticId = "SYSLIB0051")]391        protected PipelineClosedException(SerializationInfo info,392                                          StreamingContext context)393        {394            throw new NotSupportedException();395        }396        #endregion Serialization397    }398    #endregion PipelineClosedException399 400    #region ActionPreferenceStopException401    /// <summary>402    /// ActionPreferenceStopException indicates that the command stopped due403    /// to the ActionPreference.Stop or Inquire policy.404    /// </summary>405    /// <remarks>406    /// For example, if $WarningPreference is "Stop", the command will fail with407    /// this error if a cmdlet calls WriteWarning.408    /// </remarks>409    public class ActionPreferenceStopException : RuntimeException410    {411        #region ctor412        /// <summary>413        /// Instantiates a new instance of the ActionPreferenceStopException class.414        /// </summary>415        /// <returns>Constructed object.</returns>416        public ActionPreferenceStopException()417            : this(GetErrorText.ActionPreferenceStop)418        {419        }420 421        /// <summary>422        /// Instantiates a new instance of the ActionPreferenceStopException class.423        /// </summary>424        /// <param name="error">425        /// Non-terminating error which triggered the Stop426        /// </param>427        /// <returns>Constructed object.</returns>428        internal ActionPreferenceStopException(ErrorRecord error)429            : this(RetrieveMessage(error))430        {431            ArgumentNullException.ThrowIfNull(error);432 433            _errorRecord = error;434        }435 436        /// <summary>437        /// Instantiates a new instance of the ActionPreferenceStopException class.438        /// </summary>439        /// <param name="invocationInfo"></param>440        /// <param name="message"></param>441        /// <returns>Constructed object.</returns>442        internal ActionPreferenceStopException(InvocationInfo invocationInfo, string message)443            : this(message)444        {445            base.ErrorRecord.SetInvocationInfo(invocationInfo);446        }447 448        /// <summary>449        /// Instantiates a new instance of the ActionPreferenceStopException class.450        /// </summary>451        internal ActionPreferenceStopException(InvocationInfo invocationInfo,452                                               ErrorRecord errorRecord,453                                               string message)454            : this(invocationInfo, message)455        {456            ArgumentNullException.ThrowIfNull(errorRecord);457 458            _errorRecord = errorRecord;459        }460 461        #region Serialization462        /// <summary>463        /// Initializes a new instance of the ActionPreferenceStopException class464        /// using data serialized via465        /// <see cref="ISerializable"/>466        /// </summary>467        /// <param name="info">Serialization information.</param>468        /// <param name="context">Streaming context.</param>469        /// <returns>Constructed object.</returns>470        [Obsolete("Legacy serialization support is deprecated since .NET 8", DiagnosticId = "SYSLIB0051")]471        protected ActionPreferenceStopException(SerializationInfo info,472                                                StreamingContext context)473        {474            throw new NotSupportedException();475        }476        #endregion Serialization477 478        /// <summary>479        /// Instantiates a new instance of the ActionPreferenceStopException class.480        /// </summary>481        /// <param name="message"></param>482        /// <returns>Constructed object.</returns>483        public ActionPreferenceStopException(string message)484            : base(message)485        {486            SetErrorCategory(ErrorCategory.OperationStopped);487            SetErrorId("ActionPreferenceStop");488 489            // fix for BUG: Windows Out Of Band Releases: 906263 and 906264490            // The interpreter prompt CommandBaseStrings:InquireHalt491            // should be suppressed when this flag is set.  This will be set492            // when this prompt has already occurred and Break was chosen,493            // or for ActionPreferenceStopException in all cases.494            this.SuppressPromptInInterpreter = true;495        }496 497        /// <summary>498        /// Instantiates a new instance of the ActionPreferenceStopException class.499        /// </summary>500        /// <param name="message"></param>501        /// <param name="innerException"></param>502        /// <returns>Constructed object.</returns>503        public ActionPreferenceStopException(string message,504                                             Exception innerException)505            : base(message, innerException)506        {507            SetErrorCategory(ErrorCategory.OperationStopped);508            SetErrorId("ActionPreferenceStop");509 510            // fix for BUG: Windows Out Of Band Releases: 906263 and 906264511            // The interpreter prompt CommandBaseStrings:InquireHalt512            // should be suppressed when this flag is set.  This will be set513            // when this prompt has already occurred and Break was chosen,514            // or for ActionPreferenceStopException in all cases.515            this.SuppressPromptInInterpreter = true;516        }517        #endregion ctor518 519        #region Properties520        /// <summary>521        /// See <see cref="System.Management.Automation.IContainsErrorRecord"/>522        /// </summary>523        /// <value>ErrorRecord</value>524        /// <remarks>525        /// If this error results from a non-terminating error being promoted to526        /// terminating due to -ErrorAction or $ErrorActionPreference, this is527        /// the non-terminating error.528        /// </remarks>529        public override ErrorRecord ErrorRecord530        {531            get { return _errorRecord ?? base.ErrorRecord; }532        }533 534        private readonly ErrorRecord _errorRecord = null;535        #endregion Properties536    }537    #endregion ActionPreferenceStopException538 539    #region ParentContainsErrorRecordException540    /// <summary>541    /// ParentContainsErrorRecordException is the exception contained by the ErrorRecord542    /// which is associated with a PowerShell engine custom exception through543    /// the IContainsErrorRecord interface.544    /// </summary>545    /// <remarks>546    /// We use this exception class547    /// so that there is not a recursive "containment" relationship548    /// between the PowerShell engine exception and its ErrorRecord.549    /// </remarks>550    public class ParentContainsErrorRecordException : SystemException551    {552        #region Constructors553        /// <summary>554        /// Instantiates a new instance of the ParentContainsErrorRecordException class.555        /// Note that this sets the Message and not the InnerException.556        /// </summary>557        /// <returns>Constructed object.</returns>558        /// <remarks>559        /// I leave this non-standard constructor form public.560        /// </remarks>561#pragma warning disable 56506562 563        // BUGBUG : We should check whether wrapperException is not null.564        // Please remove the #pragma warning when this is fixed.565        public ParentContainsErrorRecordException(Exception wrapperException)566        {567            _wrapperException = wrapperException;568        }569 570#pragma warning restore 56506571 572        /// <summary>573        /// Instantiates a new instance of the ParentContainsErrorRecordException class.574        /// </summary>575        /// <param name="message"></param>576        /// <returns>Constructed object.</returns>577        public ParentContainsErrorRecordException(string message)578        {579            _message = message;580        }581 582        /// <summary>583        /// Instantiates a new instance of the ParentContainsErrorRecordException class.584        /// </summary>585        /// <returns>Constructed object.</returns>586        public ParentContainsErrorRecordException()587            : base()588        {589        }590 591        /// <summary>592        /// Instantiates a new instance of the ParentContainsErrorRecordException class.593        /// </summary>594        /// <param name="message"></param>595        /// <param name="innerException"></param>596        /// <returns>Constructed object.</returns>597        public ParentContainsErrorRecordException(string message,598                                                  Exception innerException)599            : base(message, innerException)600        {601            _message = message;602        }603        #endregion Constructors604 605        #region Serialization606        /// <summary>607        /// Initializes a new instance of the ParentContainsErrorRecordException class608        /// using data serialized via609        /// <see cref="ISerializable"/>610        /// </summary>611        /// <param name="info">Serialization information.</param>612        /// <param name="context">Streaming context.</param>613        /// <returns>Doesn't return.</returns>614        /// <exception cref="NotImplementedException">Always.</exception>615        [Obsolete("Legacy serialization support is deprecated since .NET 8", DiagnosticId = "SYSLIB0051")]616        protected ParentContainsErrorRecordException(617            SerializationInfo info, StreamingContext context)618        {619            throw new NotSupportedException();620        }621        #endregion Serialization622        /// <summary>623        /// Gets the message for the exception.624        /// </summary>625        public override string Message626        {627            get628            {629                return _message ??= (_wrapperException != null) ? _wrapperException.Message : string.Empty;630            }631        }632 633        #region Private Data634 635        private readonly Exception _wrapperException;636        private string _message;637 638        #endregion639    }640    #endregion ParentContainsErrorRecordException641 642    #region RedirectedException643    /// <summary>644    /// Indicates that a success object was written and success-to-error ("1>&amp;2")645    /// has been specified.646    /// </summary>647    /// <remarks>648    /// The redirected object is available as649    /// <see cref="System.Management.Automation.ErrorRecord.TargetObject"/>650    /// in the ErrorRecord which contains this exception.651    /// </remarks>652    public class RedirectedException : RuntimeException653    {654        #region constructors655        /// <summary>656        /// Instantiates a new instance of the RedirectedException class.657        /// </summary>658        /// <returns>Constructed object.</returns>659        public RedirectedException()660            : base()661        {662            SetErrorId("RedirectedException");663            SetErrorCategory(ErrorCategory.NotSpecified);664        }665 666        /// <summary>667        /// Instantiates a new instance of the RedirectedException class.668        /// </summary>669        /// <param name="message"></param>670        /// <returns>Constructed object.</returns>671        public RedirectedException(string message)672            : base(message)673        {674            SetErrorId("RedirectedException");675            SetErrorCategory(ErrorCategory.NotSpecified);676        }677 678        /// <summary>679        /// Instantiates a new instance of the RedirectedException class.680        /// </summary>681        /// <param name="message"></param>682        /// <param name="innerException"></param>683        /// <returns>Constructed object.</returns>684        public RedirectedException(string message,685                                   Exception innerException)686            : base(message, innerException)687        {688            SetErrorId("RedirectedException");689            SetErrorCategory(ErrorCategory.NotSpecified);690        }691 692        /// <summary>693        /// Initializes a new instance of the RedirectedException class694        /// using data serialized via695        /// <see cref="ISerializable"/>696        /// </summary>697        /// <param name="info">Serialization information.</param>698        /// <param name="context">Streaming context.</param>699        /// <returns>Constructed object.</returns>700        [Obsolete("Legacy serialization support is deprecated since .NET 8", DiagnosticId = "SYSLIB0051")]701        protected RedirectedException(SerializationInfo info,702                                      StreamingContext context)703        {704            throw new NotSupportedException();705        }706        #endregion constructors707    }708    #endregion RedirectedException709 710    #region ScriptCallDepthException711    /// <summary>712    /// ScriptCallDepthException occurs when the number of713    /// session state objects of this type in this scope714    /// exceeds the configured maximum.715    /// </summary>716    /// <remarks>717    /// When one PowerShell command or script calls another, this creates an additional718    /// scope.  Some script expressions also create a scope.  PowerShell imposes a maximum719    /// call depth to prevent stack overflows.  The maximum call depth is configurable720    /// but generally high enough that scripts which are not deeply recursive721    /// should not have a problem.722    /// </remarks>723    public class ScriptCallDepthException : SystemException, IContainsErrorRecord724    {725        #region ctor726 727        /// <summary>728        /// Instantiates a new instance of the ScriptCallDepthException class.729        /// </summary>730        /// <returns>Constructed object.</returns>731        public ScriptCallDepthException()732            : base(GetErrorText.ScriptCallDepthException)733        {734        }735 736        /// <summary>737        /// Instantiates a new instance of the ScriptCallDepthException class.738        /// </summary>739        /// <param name="message"></param>740        /// <returns>Constructed object.</returns>741        public ScriptCallDepthException(string message)742            : base(message)743        {744        }745 746        /// <summary>747        /// Instantiates a new instance of the ScriptCallDepthException class.748        /// </summary>749        /// <param name="message"></param>750        /// <param name="innerException"></param>751        /// <returns>Constructed object.</returns>752        public ScriptCallDepthException(string message,753                                        Exception innerException)754                : base(message, innerException)755        {756        }757        #endregion ctor758 759        #region Serialization760        /// <summary>761        /// Initializes a new instance of the ScriptCallDepthException class762        /// using data serialized via763        /// <see cref="ISerializable"/>764        /// </summary>765        /// <param name="info">Serialization information.</param>766        /// <param name="context">Streaming context.</param>767        /// <returns>Constructed object.</returns>768        [Obsolete("Legacy serialization support is deprecated since .NET 8", DiagnosticId = "SYSLIB0051")]769        protected ScriptCallDepthException(SerializationInfo info,770                                           StreamingContext context)771        {772            throw new NotSupportedException();773        }774        #endregion Serialization775 776        #region properties777        /// <summary>778        /// See <see cref="System.Management.Automation.IContainsErrorRecord"/>779        /// </summary>780        /// <value></value>781        /// <remarks>782        /// TargetObject is the offending call depth783        /// </remarks>784        public ErrorRecord ErrorRecord785        {786            get787            {788                _errorRecord ??= new ErrorRecord(789                    new ParentContainsErrorRecordException(this),790                    "CallDepthOverflow",791                    ErrorCategory.InvalidOperation,792                    CallDepth);793 794                return _errorRecord;795            }796        }797 798        private ErrorRecord _errorRecord = null;799 800        /// <summary>801        /// Always 0 - depth is not tracked as there is no hard coded maximum.802        /// </summary>803        public int CallDepth804        {805            get { return 0; }806        }807        #endregion properties808    }809    #endregion ScriptCallDepthException810 811    #region PipelineDepthException812    /// <summary>813    /// PipelineDepthException occurs when the number of814    /// commands participating in a pipeline (object streaming)815    /// exceeds the configured maximum.816    /// </summary>817    /// <remarks>818    /// </remarks>819    public class PipelineDepthException : SystemException, IContainsErrorRecord820    {821        #region ctor822        /// <summary>823        /// Instantiates a new instance of the PipelineDepthException class.824        /// </summary>825        /// <returns>Constructed object.</returns>826        public PipelineDepthException()827            : base(GetErrorText.PipelineDepthException)828        {829        }830 831        /// <summary>832        /// Instantiates a new instance of the PipelineDepthException class.833        /// </summary>834        /// <param name="message"></param>835        /// <returns>Constructed object.</returns>836        public PipelineDepthException(string message)837            : base(message)838        {839        }840 841        /// <summary>842        /// Instantiates a new instance of the PipelineDepthException class.843        /// </summary>844        /// <param name="message"></param>845        /// <param name="innerException"></param>846        /// <returns>Constructed object.</returns>847        public PipelineDepthException(string message,848                                        Exception innerException)849            : base(message, innerException)850        {851        }852        #endregion ctor853 854        #region Serialization855        /// <summary>856        /// Initializes a new instance of the PipelineDepthException class857        /// using data serialized via858        /// <see cref="ISerializable"/>859        /// </summary>860        /// <param name="info">Serialization information.</param>861        /// <param name="context">Streaming context.</param>862        /// <returns>Constructed object.</returns>863        [Obsolete("Legacy serialization support is deprecated since .NET 8", DiagnosticId = "SYSLIB0051")]864        protected PipelineDepthException(SerializationInfo info,865                                           StreamingContext context)866        {867            throw new NotSupportedException();868        }869        #endregion Serialization870 871        #region properties872        /// <summary>873        /// See <see cref="System.Management.Automation.IContainsErrorRecord"/>874        /// </summary>875        /// <value></value>876        /// <remarks>877        /// TargetObject is the offending call depth878        /// </remarks>879        [SuppressMessage("Microsoft.Design", "CA1065:DoNotRaiseExceptionsInUnexpectedLocations")]880        public ErrorRecord ErrorRecord881        {882            get883            {884                _errorRecord ??= new ErrorRecord(885                    new ParentContainsErrorRecordException(this),886                    "CallDepthOverflow",887                    ErrorCategory.InvalidOperation,888                    CallDepth);889 890                return _errorRecord;891            }892        }893 894        private ErrorRecord _errorRecord = null;895 896        /// <summary>897        /// Always 0 - depth is not tracked as there is no hard coded maximum.898        /// </summary>899        /// <value></value>900        public int CallDepth901        {902            get { return 0; }903        }904        #endregion properties905    }906    #endregion907 908    #region HaltCommandException909    /// <summary>910    /// A cmdlet/provider should throw HaltCommandException911    /// when it wants to terminate the running command without912    /// this being considered an error.913    /// </summary>914    /// <remarks>915    /// For example, "more" will throw HaltCommandException if the user hits "q".916    ///917    /// Only throw HaltCommandException from your implementation of ProcessRecord etc.918    ///919    /// Note that HaltCommandException does not define IContainsErrorRecord.920    /// This is because it is not reported to the user.921    /// </remarks>922    public class HaltCommandException : SystemException923    {924        #region ctor925        /// <summary>926        /// Instantiates a new instance of the HaltCommandException class.927        /// </summary>928        /// <returns>Constructed object.</returns>929        public HaltCommandException()930            : base(StringUtil.Format(AutomationExceptions.HaltCommandException))931        {932        }933 934        /// <summary>935        /// Instantiates a new instance of the HaltCommandException class.936        /// </summary>937        /// <param name="message"></param>938        /// <returns>Constructed object.</returns>939        public HaltCommandException(string message)940            : base(message)941        {942        }943 944        /// <summary>945        /// Instantiates a new instance of the HaltCommandException class.946        /// </summary>947        /// <param name="message"></param>948        /// <param name="innerException"></param>949        /// <returns>Constructed object.</returns>950        public HaltCommandException(string message,951                                    Exception innerException)952            : base(message, innerException)953        {954        }955        #endregion ctor956 957        #region Serialization958        /// <summary>959        /// Initializes a new instance of the HaltCommandException class960        /// using data serialized via961        /// <see cref="ISerializable"/>962        /// </summary>963        /// <param name="info">Serialization information.</param>964        /// <param name="context">Streaming context.</param>965        /// <returns>Constructed object.</returns>966        [Obsolete("Legacy serialization support is deprecated since .NET 8", DiagnosticId = "SYSLIB0051")]967        protected HaltCommandException(SerializationInfo info,968                                       StreamingContext context)969        {970            throw new NotSupportedException();971        }972        #endregion Serialization973    }974    #endregion HaltCommandException975}976 977#pragma warning restore 56506978