本文整理汇总了C#中System.FormatException类的典型用法代码示例。如果您正苦于以下问题:C# FormatException类的具体用法?C# FormatException怎么用?C# FormatException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
FormatException类属于System命名空间,在下文中一共展示了FormatException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ConstructorWithMessageAndInnerExceptionWorks
public void ConstructorWithMessageAndInnerExceptionWorks() {
var inner = new Exception("a");
var ex = new FormatException("The message", inner);
Assert.IsTrue((object)ex is FormatException, "is FormatException");
Assert.IsTrue(ReferenceEquals(ex.InnerException, inner), "InnerException");
Assert.AreEqual(ex.Message, "The message");
}
示例2: InstantiateException
public static void InstantiateException()
{
int error = 5;
string message = "This is an error message.";
Exception innerException = new FormatException();
// Test each of the constructors and validate the properties of the resulting instance
Win32Exception ex = new Win32Exception();
Assert.Equal(expected: E_FAIL, actual: ex.HResult);
ex = new Win32Exception(error);
Assert.Equal(expected: E_FAIL, actual: ex.HResult);
Assert.Equal(expected: error, actual: ex.NativeErrorCode);
ex = new Win32Exception(message);
Assert.Equal(expected: E_FAIL, actual: ex.HResult);
Assert.Equal(expected: message, actual: ex.Message);
ex = new Win32Exception(error, message);
Assert.Equal(expected: E_FAIL, actual: ex.HResult);
Assert.Equal(expected: error, actual: ex.NativeErrorCode);
Assert.Equal(expected: message, actual: ex.Message);
ex = new Win32Exception(message, innerException);
Assert.Equal(expected: E_FAIL, actual: ex.HResult);
Assert.Equal(expected: message, actual: ex.Message);
Assert.Same(expected: innerException, actual: ex.InnerException);
}
示例3: ConstructorWithMessageWorks
public void ConstructorWithMessageWorks()
{
var ex = new FormatException("The message");
Assert.True((object)ex is FormatException, "is FormatException");
Assert.AreEqual(ex.InnerException, null, "InnerException");
Assert.AreEqual(ex.Message, "The message");
}
示例4: DefaultConstructorWorks
public void DefaultConstructorWorks()
{
var ex = new FormatException();
Assert.True((object)ex is FormatException, "is FormatException");
Assert.AreEqual(ex.InnerException, null, "InnerException");
Assert.AreEqual(ex.Message, "Invalid format.");
}
示例5: TypePropertiesAreCorrect
public void TypePropertiesAreCorrect()
{
Assert.AreEqual(typeof(FormatException).GetClassName(), "Bridge.FormatException", "Name");
object d = new FormatException();
Assert.True(d is FormatException, "is FormatException");
Assert.True(d is Exception, "is Exception");
}
示例6: ConvertFrom
public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
{
var stringValue = value as string;
if (stringValue != null)
{
var input = stringValue.Trim();
if (string.IsNullOrEmpty(input))
{
return value;
}
// Try to parse. Use the invariant culture instead of the current one.
TimeSpan timeSpan;
if (TimeSpan.TryParse(input, CultureInfo.InvariantCulture, out timeSpan))
{
return value;
}
var exception = new FormatException(string.Format(CultureInfo.CurrentCulture, Resources.TimeSpanConverter_InvalidString, stringValue));
throw exception;
}
return base.ConvertFrom(context, culture, value);
}
示例7: AddParameter
internal static string AddParameter (string baseUrl, string parameter, string value)
{
// this will get our url's properly formatted
if (parameter == Constants.UrlParameter.Url)
{
try
{
value = new Uri (value).ToString();
}
catch (System.FormatException e) //UriFormatException is not supported in the portable libraries
{
FormatException ufe = new FormatException("Delicious.Net was unable to parse the url \"" + value + "\".\n\n" + e);
throw (ufe);
}
}
value = Uri.EscapeDataString(value); //HttpUtility.UrlEncode is not supported in the portable libraries
// insert the '?' if needed
int qLocation = baseUrl.LastIndexOf ('?');
if (qLocation < 0)
{
baseUrl += "?";
qLocation = baseUrl.Length - 1;
}
if (baseUrl.Length > qLocation + 1)
baseUrl += "&";
baseUrl += parameter + "=" + value;
return baseUrl;
}
示例8: TestWhenAny1_Canceled1_Faulted1
public void TestWhenAny1_Canceled1_Faulted1()
{
Exception expectedException = new FormatException();
Action<Task> exceptionSelector =
task =>
{
throw expectedException;
};
IEnumerable<Task> tasks =
new[]
{
DelayedTask.Delay(TimeSpan.FromMilliseconds(1 * TimingGranularity.TotalMilliseconds)).Then(_ => CompletedTask.Canceled()),
DelayedTask.Delay(TimeSpan.FromMilliseconds(3 * TimingGranularity.TotalMilliseconds)).Select(exceptionSelector).ObserveExceptions()
};
Task<Task> delayed = DelayedTask.WhenAny(tasks);
Assert.IsFalse(delayed.IsCompleted);
delayed.Wait();
Assert.IsTrue(delayed.IsCompleted);
Assert.AreEqual(TaskStatus.RanToCompletion, delayed.Status);
Assert.IsNotNull(delayed.Result);
Assert.IsTrue(tasks.Contains(delayed.Result));
// this one was the first to complete
Assert.IsTrue(delayed.Result.IsCompleted);
Assert.IsTrue(delayed.Result.IsCanceled);
Assert.AreEqual(TaskStatus.Canceled, delayed.Result.Status);
}
示例9: DisplayException
internal static void DisplayException(FormatException exception)
{
var title = "Format exception";
StringBuilder content = new StringBuilder();
content.AppendLine("There is a problem with the format of the message:");
content.AppendFormat("Exception: {0}\n\n", exception.Message);
MessageDialogHelper.ShowDialogAsync(content.ToString(), title);
}
示例10: InvariantWithLambdaMessageAndInnerThrowsCorrectly
public void InvariantWithLambdaMessageAndInnerThrowsCorrectly()
{
FormatException inner = new FormatException();
Assert.That(() => Check.Invariant(-1, i => i > 0, InvariantMessage, inner),
Throws.TypeOf<InvariantException>()
.With.Message.ContainsSubstring(InvariantMessage)
.And.Property("InnerException").EqualTo(inner));
}
示例11: AssertionWithMessageAndInnerThrowsCorrectly
public void AssertionWithMessageAndInnerThrowsCorrectly()
{
FormatException inner = new FormatException();
Assert.That(() => Check.Assert(false, AssertionMessage, inner),
Throws.TypeOf<AssertionException>()
.With.Message.ContainsSubstring(AssertionMessage)
.And.Property("InnerException").EqualTo(inner));
}
示例12: PostconditionWithLambdaMessageAndInnerThrowsCorrectly
public void PostconditionWithLambdaMessageAndInnerThrowsCorrectly()
{
FormatException inner = new FormatException();
Assert.That(() => Check.Ensure(-1, i => i > 0, PostconditionMessage, inner),
Throws.TypeOf<PostconditionException>()
.With.Message.ContainsSubstring(PostconditionMessage)
.And.Property("InnerException").EqualTo(inner));
}
示例13: InputNotANumberLog
public static void InputNotANumberLog(FormatException e)
{
List<string> log = new List<string>();
log.Add("InputNotANumberError");
log.Add("Fehlermeldung: " + e.Message);
log.Add("Fehler bei der Auswahl des Songs.");
log.Add("Fehlerbehebung: Programm mit Song erneut starten, nur 1, 2 oder 3 eingeben.");
Errorlogs.PrintLogs(log);
}
示例14: ShouldFlattenTheException
public void ShouldFlattenTheException()
{
var formatException = new FormatException("FormatException Message");
var argumentNullException = new ArgumentNullException("ArgumentNullException Message", formatException);
var exception = new Exception("Exception Message", argumentNullException);
var exceptionFlatten = exception.Flatten();
const string messageExpected = "Exception Message\r\nArgumentNullException Message\r\nFormatException Message\r\n";
Assert.AreEqual(messageExpected, exceptionFlatten);
}
示例15: ShouldFindTheSpecifiedException
public void ShouldFindTheSpecifiedException()
{
var formatException = new FormatException();
var argumentNullException = new ArgumentNullException("", formatException);
var exception = new Exception("", argumentNullException);
var foundException = exception.Find<ArgumentNullException>();
Assert.IsNotNull(foundException);
Assert.IsInstanceOf(typeof(ArgumentNullException), foundException);
}