/********************************************************************++ Copyright (c) Microsoft Corporation. All rights reserved. --********************************************************************/ using System.Runtime.Serialization; namespace System.Management.Automation { /// /// This is a wrapper for exception class SecurityException /// [Serializable] public class PSSecurityException : RuntimeException { #region ctor /// /// Recommended constructor for class PSSecurityException /// /// constructed object public PSSecurityException() : base() { _errorRecord = new ErrorRecord( new ParentContainsErrorRecordException(this), "UnauthorizedAccess", ErrorCategory.SecurityError, null); _errorRecord.ErrorDetails = new ErrorDetails(SessionStateStrings.CanNotRun); _message = _errorRecord.ErrorDetails.Message; } /// /// Serialization constructor for class PSSecurityException /// /// serialization information /// streaming context /// constructed object protected PSSecurityException(SerializationInfo info, StreamingContext context) : base(info, context) { _errorRecord = new ErrorRecord( new ParentContainsErrorRecordException(this), "UnauthorizedAccess", ErrorCategory.SecurityError, null); _errorRecord.ErrorDetails = new ErrorDetails(SessionStateStrings.CanNotRun); _message = _errorRecord.ErrorDetails.Message; // no fields, nothing more to serialize // no need for a GetObjectData implementation } /// /// Constructor for class PSSecurityException /// /// /// constructed object public PSSecurityException(string message) : base(message) { _message = message; _errorRecord = new ErrorRecord( new ParentContainsErrorRecordException(this), "UnauthorizedAccess", ErrorCategory.SecurityError, null); _errorRecord.ErrorDetails = new ErrorDetails(message); } /// /// Constructor for class PSSecurityException /// /// /// /// constructed object public PSSecurityException(string message, Exception innerException) : base(message, innerException) { _errorRecord = new ErrorRecord( new ParentContainsErrorRecordException(this), "UnauthorizedAccess", ErrorCategory.SecurityError, null); _errorRecord.ErrorDetails = new ErrorDetails(message); _message = _errorRecord.ErrorDetails.Message; } #endregion ctor /// /// Gets the ErrorRecord information for this exception. /// public override ErrorRecord ErrorRecord { get { if (null == _errorRecord) { _errorRecord = new ErrorRecord( new ParentContainsErrorRecordException(this), "UnauthorizedAccess", ErrorCategory.SecurityError, null); } return _errorRecord; } } private ErrorRecord _errorRecord; /// /// Exception.Message is get-only, but you can effectively /// set it in a subclass by overriding this virtual property. /// /// public override string Message { get { return _message; } } private string _message; } // PSSecurityException } // System.Management.Automation