ExceptionUtil
using System.Configuration.Internal;
using System.Xml;
namespace System.Configuration
{
internal static class ExceptionUtil
{
internal static string NoExceptionInformation => System.SR.No_exception_information_available;
internal static ArgumentException ParameterInvalid(string parameter)
{
return new ArgumentException(System.SR.Format(System.SR.Parameter_Invalid, parameter), parameter);
}
internal static ArgumentException ParameterNullOrEmpty(string parameter)
{
return new ArgumentException(System.SR.Format(System.SR.Parameter_NullOrEmpty, parameter), parameter);
}
internal static ArgumentException PropertyInvalid(string property)
{
return new ArgumentException(System.SR.Format(System.SR.Property_Invalid, property), property);
}
internal static ArgumentException PropertyNullOrEmpty(string property)
{
return new ArgumentException(System.SR.Format(System.SR.Property_NullOrEmpty, property), property);
}
internal static InvalidOperationException UnexpectedError(string methodName)
{
return new InvalidOperationException(System.SR.Format(System.SR.Unexpected_Error, methodName));
}
internal static ConfigurationErrorsException WrapAsConfigException(string outerMessage, Exception e, IConfigErrorInfo errorInfo)
{
if (errorInfo == null)
return WrapAsConfigException(outerMessage, e, null, 0);
return WrapAsConfigException(outerMessage, e, errorInfo.Filename, errorInfo.LineNumber);
}
internal static ConfigurationErrorsException WrapAsConfigException(string outerMessage, Exception e, string filename, int line)
{
ConfigurationErrorsException ex = e as ConfigurationErrorsException;
if (ex != null)
return ex;
ConfigurationException ex2 = e as ConfigurationException;
if (ex2 != null)
return new ConfigurationErrorsException(ex2.BareMessage, ex2.InnerException, ex2.Filename, ex2.Line);
XmlException ex3 = e as XmlException;
if (ex3 != null) {
if (ex3.LineNumber != 0)
line = ex3.LineNumber;
return new ConfigurationErrorsException(ex3.Message, ex3, filename, line);
}
if (e != null)
return new ConfigurationErrorsException(System.SR.Format(System.SR.Wrapped_exception_message, outerMessage, e.Message), e, filename, line);
return new ConfigurationErrorsException(System.SR.Format(System.SR.Wrapped_exception_message, outerMessage, NoExceptionInformation), filename, line);
}
}
}