예제 #1
0
 /// <summary>
 /// Creates a container filled with the first exception.
 /// </summary>
 /// <param name="Exception"></param>
 public DbatoolsExceptionRecord(DbatoolsException Exception)
 {
     Runspace     = Exception.Runspace;
     Timestamp    = Exception.Timestamp;
     FunctionName = Exception.FunctionName;
     Message      = Exception.Message;
 }
예제 #2
0
        /// <summary>
        /// Creates an exception based on an original exception object
        /// </summary>
        /// <param name="Except">The exception to wrap around</param>
        public DbatoolsException(Exception Except)
        {
            _Exception = Except;

            Message    = Except.Message;
            Source     = Except.Source;
            StackTrace = Except.StackTrace;
            try { TargetSite = Except.TargetSite.ToString(); }
            catch { }
            HResult  = Except.HResult;
            HelpLink = Except.HelpLink;
            Data     = Except.Data;
            if (Except.InnerException != null)
            {
                InnerException = new DbatoolsException(Except.InnerException);
            }

            ExceptionTypeName = Except.GetType().FullName;

            PSObject      tempObject           = new PSObject(Except);
            List <string> defaultPropertyNames = new List <string>();

            defaultPropertyNames.Add("Data");
            defaultPropertyNames.Add("HelpLink");
            defaultPropertyNames.Add("HResult");
            defaultPropertyNames.Add("InnerException");
            defaultPropertyNames.Add("Message");
            defaultPropertyNames.Add("Source");
            defaultPropertyNames.Add("StackTrace");
            defaultPropertyNames.Add("TargetSite");

            foreach (PSPropertyInfo member in tempObject.Properties)
            {
                if (!defaultPropertyNames.Contains(member.Name))
                {
                    ExceptionData[member.Name] = member.Value;
                }
            }
        }