Team Ai
Datasetpublic

MegaBites-AI/Windows-powershell

sourceHugging Facemitupdated 6mo agoView on Hugging Face
0likes308downloads
HostInterfacesExceptions.cs229 linesDownload Raw Back to utils
1// Copyright (c) Microsoft Corporation.2// Licensed under the MIT License.3 4using System.Management.Automation.Internal;5using System.Runtime.Serialization;6 7namespace System.Management.Automation.Host8{9    /// <summary>10    /// Defines the exception thrown when the Host cannot complete an operation11    /// such as checking whether there is any input available.12    /// </summary>13    public14    class HostException : RuntimeException15    {16        #region ctors17        /// <summary>18        /// Initializes a new instance of the HostException class.19        /// </summary>20        public21        HostException()22            : base(StringUtil.Format(HostInterfaceExceptionsStrings.DefaultCtorMessageTemplate, typeof(HostException).FullName))23        {24            SetDefaultErrorRecord();25        }26 27        /// <summary>28        /// Initializes a new instance of the HostException class and defines the error message.29        /// </summary>30        /// <param name="message">31        /// The error message that explains the reason for the exception.32        /// </param>33        public34        HostException(string message)35            : base(message)36        {37            SetDefaultErrorRecord();38        }39 40        /// <summary>41        /// Initializes a new instance of the HostException class and defines the error message and42        /// inner exception.43        /// </summary>44        /// <param name="message">45        /// The error message that explains the reason for the exception.46        /// </param>47        /// <param name="innerException">48        /// The exception that is the cause of the current exception. If the <paramref name="innerException"/>49        /// parameter is not a null reference, the current exception is raised in a catch50        /// block that handles the inner exception.51        /// </param>52        public53        HostException(string message, Exception innerException)54            : base(message, innerException)55        {56            SetDefaultErrorRecord();57        }58 59        /// <summary>60        /// Initializes a new instance of the HostException class and defines the error message,61        /// inner exception, the error ID, and the error category.62        /// </summary>63        /// <param name="message">64        /// The error message that explains the reason for the exception.65        /// </param>66        /// <param name="innerException">67        /// The exception that is the cause of the current exception. If the <paramref name="innerException"/>68        /// parameter is not a null reference, the current exception is raised in a catch69        /// block that handles the inner exception.70        /// </param>71        /// <param name="errorId">72        /// The string that should uniquely identifies the situation where the exception is thrown.73        /// The string should not contain white space.74        /// </param>75        /// <param name="errorCategory">76        /// The ErrorCategory into which this exception situation falls77        /// </param>78        /// <remarks>79        /// Intentionally public, third-party hosts can call this80        /// </remarks>81        public82        HostException(83            string message,84            Exception innerException,85            string errorId,86            ErrorCategory errorCategory)87            : base(message, innerException)88        {89            SetErrorId(errorId);90            SetErrorCategory(errorCategory);91        }92 93        /// <summary>94        /// Initializes a new instance of the HostException class and defines the SerializationInfo95        /// and the StreamingContext.96        /// </summary>97        /// <param name="info">98        /// The object that holds the serialized object data.99        /// </param>100        /// <param name="context">101        /// The contextual information about the source or destination.102        /// </param>103        [Obsolete("Legacy serialization support is deprecated since .NET 8", DiagnosticId = "SYSLIB0051")]104        protected105        HostException(SerializationInfo info, StreamingContext context)106        {107            throw new NotSupportedException();108        }109 110        #endregion111        #region private112        private void SetDefaultErrorRecord()113        {114            SetErrorCategory(ErrorCategory.ResourceUnavailable);115            SetErrorId(typeof(HostException).FullName);116        }117        #endregion118 119    }120 121    /// <summary>122    /// Defines the exception thrown when an error occurs from prompting for a command parameter.123    /// </summary>124    public125    class PromptingException : HostException126    {127        #region ctors128        /// <summary>129        /// Initializes a new instance of the PromptingException class.130        /// </summary>131        public132        PromptingException()133            : base(StringUtil.Format(HostInterfaceExceptionsStrings.DefaultCtorMessageTemplate, typeof(PromptingException).FullName))134        {135            SetDefaultErrorRecord();136        }137 138        /// <summary>139        /// Initializes a new instance of the PromptingException class and defines the error message.140        /// </summary>141        /// <param name="message">142        /// The error message that explains the reason for the exception.143        /// </param>144        public145        PromptingException(string message)146            : base(message)147        {148            SetDefaultErrorRecord();149        }150 151        /// <summary>152        /// Initializes a new instance of the PromptingException class and defines the error message and153        /// inner exception.154        /// </summary>155        /// <param name="message">156        /// The error message that explains the reason for the exception.157        /// </param>158        /// <param name="innerException">159        /// The exception that is the cause of the current exception. If the <paramref name="innerException"/>160        /// parameter is not a null reference, the current exception is raised in a catch161        /// block that handles the inner exception.162        /// </param>163        public164        PromptingException(string message, Exception innerException)165            : base(message, innerException)166        {167            SetDefaultErrorRecord();168        }169 170        /// <summary>171        /// Initializes a new instance of the PromptingException class and defines the error message,172        /// inner exception, the error ID, and the error category.173        /// </summary>174        /// <param name="message">175        /// The error message that explains the reason for the exception.176        /// </param>177        /// <param name="innerException">178        /// The exception that is the cause of the current exception. If the <paramref name="innerException"/>179        /// parameter is not a null reference, the current exception is raised in a catch180        /// block that handles the inner exception.181        /// </param>182        /// <param name="errorId">183        /// The string that should uniquely identifies the situation where the exception is thrown.184        /// The string should not contain white space.185        /// </param>186        /// <param name="errorCategory">187        /// The ErrorCategory into which this exception situation falls188        /// </param>189        /// <remarks>190        /// Intentionally public, third-party hosts can call this191        /// </remarks>192        public193        PromptingException(194            string message,195            Exception innerException,196            string errorId,197            ErrorCategory errorCategory)198            : base(message, innerException, errorId, errorCategory)199        {200        }201 202        /// <summary>203        /// Initializes a new instance of the HostException class and defines the SerializationInfo204        /// and the StreamingContext.205        /// </summary>206        /// <param name="info">207        /// The object that holds the serialized object data.208        /// </param>209        /// <param name="context">210        /// The contextual information about the source or destination.211        /// </param>212        [Obsolete("Legacy serialization support is deprecated since .NET 8", DiagnosticId = "SYSLIB0051")]213        protected214        PromptingException(SerializationInfo info, StreamingContext context)215        {216            throw new NotSupportedException();217        }218        #endregion219 220        #region private221        private void SetDefaultErrorRecord()222        {223            SetErrorCategory(ErrorCategory.ResourceUnavailable);224            SetErrorId(typeof(PromptingException).FullName);225        }226        #endregion227    }228}229