System.Configuration.ExceptionUtil.WrapAsConfigException C# (CSharp) Метод

WrapAsConfigException() статический приватный Метод

static private WrapAsConfigException ( string outerMessage, Exception e, string filename, int line ) : ConfigurationErrorsException
outerMessage string
e System.Exception
filename string
line int
Результат ConfigurationErrorsException
        static internal ConfigurationErrorsException WrapAsConfigException(string outerMessage, Exception e, string filename, int line) {
            //
            // Preserve ConfigurationErrorsException
            //
            ConfigurationErrorsException ce = e as ConfigurationErrorsException;
            if (ce != null) {
                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);
        }
    }

Same methods

ExceptionUtil::WrapAsConfigException ( string outerMessage, Exception e, IConfigErrorInfo errorInfo ) : ConfigurationErrorsException

Usage Example

        public override XmlNode ProcessRawXml(XmlNode rawXml)
        {
            XmlNode processedXml       = rawXml;
            String  currentBuilderName = null;

            try {
                foreach (ConfigurationBuilder b in _builders)
                {
                    currentBuilderName = b.Name;
                    processedXml       = b.ProcessRawXml(processedXml);
                }
                return(processedXml);
            }
            catch (Exception e) {
                throw ExceptionUtil.WrapAsConfigException(SR.GetString(SR.ConfigBuilder_processXml_error_short,
                                                                       currentBuilderName), e, null);
            }
        }
All Usage Examples Of System.Configuration.ExceptionUtil::WrapAsConfigException