MegaBites-AI/Windows-powershell
0372
1// Copyright (c) Microsoft Corporation.2// Licensed under the MIT License.3 4using System.Runtime.Serialization;5 6namespace System.Management.Automation7{8 /// <summary>9 /// This is a wrapper for exception class10 /// <see cref="System.ArgumentOutOfRangeException"/>11 /// which provides additional information via12 /// <see cref="System.Management.Automation.IContainsErrorRecord"/>.13 /// </summary>14 /// <remarks>15 /// Instances of this exception class are usually generated by the16 /// PowerShell Engine. It is unusual for code outside the PowerShell Engine17 /// to create an instance of this class.18 /// </remarks>19 public class PSArgumentOutOfRangeException20 : ArgumentOutOfRangeException, IContainsErrorRecord21 {22 #region ctor23 /// <summary>24 /// Constructor for class PSArgumentOutOfRangeException.25 /// </summary>26 /// <returns>Constructed object.</returns>27 public PSArgumentOutOfRangeException()28 : base()29 {30 }31 32 /// <summary>33 /// Initializes a new instance of the PSArgumentOutOfRangeException class.34 /// </summary>35 /// <param name="paramName"></param>36 /// <returns>Constructed object.</returns>37 /// <remarks>38 /// Per MSDN, the parameter is paramName and not message.39 /// I confirm this experimentally as well.40 /// </remarks>41 public PSArgumentOutOfRangeException(string paramName)42 : base(paramName)43 {44 }45 46 /// <summary>47 /// Initializes a new instance of the PSArgumentOutOfRangeException class.48 /// </summary>49 /// <param name="paramName"></param>50 /// <param name="actualValue"></param>51 /// <param name="message"></param>52 /// <returns>Constructed object.</returns>53 /// <remarks>54 /// ArgumentOutOfRangeException has this ctor form and we imitate it here.55 /// </remarks>56 public PSArgumentOutOfRangeException(string paramName, object actualValue, string message)57 : base(paramName, actualValue, message)58 {59 }60 61 #region Serialization62 /// <summary>63 /// Initializes a new instance of the PSArgumentOutOfRangeException class64 /// using data serialized via65 /// <see cref="System.Runtime.Serialization.ISerializable"/>66 /// </summary>67 /// <param name="info">Serialization information.</param>68 /// <param name="context">Streaming context.</param>69 /// <returns>Constructed object.</returns>70 [Obsolete("Legacy serialization support is deprecated since .NET 8", DiagnosticId = "SYSLIB0051")]71 protected PSArgumentOutOfRangeException(SerializationInfo info,72 StreamingContext context)73 {74 throw new NotSupportedException();75 }76 77 #endregion Serialization78 79 /// <summary>80 /// Initializes a new instance of the PSArgumentOutOfRangeException class.81 /// </summary>82 /// <param name="message"></param>83 /// <param name="innerException"></param>84 /// <returns>Constructed object.</returns>85 public PSArgumentOutOfRangeException(string message,86 Exception innerException)87 : base(message, innerException)88 {89 }90 #endregion ctor91 92 /// <summary>93 /// Additional information about the error.94 /// </summary>95 /// <value></value>96 /// <remarks>97 /// Note that ErrorRecord.Exception is98 /// <see cref="System.Management.Automation.ParentContainsErrorRecordException"/>.99 /// </remarks>100 public ErrorRecord ErrorRecord101 {102 get103 {104 _errorRecord ??= new ErrorRecord(105 new ParentContainsErrorRecordException(this),106 _errorId,107 ErrorCategory.InvalidArgument,108 null);109 110 return _errorRecord;111 }112 }113 114 private ErrorRecord _errorRecord;115 private readonly string _errorId = "ArgumentOutOfRange";116 }117}118 