本文整理匯總了C#中System.InvalidOperationException.FormatMessage方法的典型用法代碼示例。如果您正苦於以下問題:C# InvalidOperationException.FormatMessage方法的具體用法?C# InvalidOperationException.FormatMessage怎麽用?C# InvalidOperationException.FormatMessage使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類System.InvalidOperationException
的用法示例。
在下文中一共展示了InvalidOperationException.FormatMessage方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: Stack_CreateFromAggregatedExceptionWithInnerException
public void Stack_CreateFromAggregatedExceptionWithInnerException()
{
bool caughtException = false;
try
{
File.Create(Path.GetInvalidFileNameChars()[0].ToString(), 0);
}
catch (ArgumentException exception)
{
var innerException1 = new InvalidOperationException("Test exception 1.");
var innerException2 = new InvalidOperationException("Test exception 2.", exception);
var aggregated = new AggregateException(innerException1, innerException2);
IList<Stack> stacks = Stack.CreateStacks(aggregated).ToList();
stacks.Count.Should().Be(4);
aggregated.StackTrace.Should().Be(null);
Assert.AreEqual("[No frames]", stacks[0].ToString());
Assert.AreEqual("[No frames]", stacks[1].ToString());
Assert.AreEqual("[No frames]", stacks[2].ToString());
Assert.AreEqual(exception.StackTrace, stacks[3].ToString());
Assert.AreEqual(aggregated.FormatMessage(), stacks[0].Message);
Assert.AreEqual(innerException1.FormatMessage(), stacks[1].Message);
Assert.AreEqual(innerException2.FormatMessage(), stacks[2].Message);
Assert.AreEqual(exception.FormatMessage(), stacks[3].Message);
caughtException = true;
}
Assert.IsTrue(caughtException);
}