コード例 #1
0
        static internal ConfigurationErrorsException WrapAsConfigException(string outerMessage, Exception e, string filename, int line)
        {
            //
            // Preserve ConfigurationErrorsException
            //
            ConfigurationErrorsException ce = e as ConfigurationErrorsException;

            if (ce != null)
            {
                // Well... mostly preserve. Add file/line info if it's missing.
                if ((filename != null) && (ce.Filename == null))
                {
                    ce.SetFileAndLine(filename, line);
                }
                return(ce);
            }

            //
            // Promote deprecated ConfigurationException to ConfigurationErrorsException
            //
            ConfigurationException deprecatedException = e as ConfigurationException;

            if (deprecatedException != null)
            {
                return(new ConfigurationErrorsException(deprecatedException));
            }

            //
            // For XML exceptions, preserve the text of the exception in the outer message.
            //
            XmlException xe = e as XmlException;

            if (xe != null)
            {
                if (xe.LineNumber != 0)
                {
                    line = xe.LineNumber;
                }

                return(new ConfigurationErrorsException(xe.Message, xe, filename, line));
            }

            //
            // Wrap other exceptions in an inner exception, and give as much info as possible
            //
            if (e != null)
            {
                return(new ConfigurationErrorsException(
                           SR.GetString(SR.Wrapped_exception_message, outerMessage, e.Message),
                           e,
                           filename,
                           line));
            }

            //
            // If there is no exception, create a new exception with no further information.
            //
            return(new ConfigurationErrorsException(
                       SR.GetString(SR.Wrapped_exception_message, outerMessage, ExceptionUtil.NoExceptionInformation),
                       filename,
                       line));
        }