paulirwin commented on code in PR #1101:
URL: https://github.com/apache/lucenenet/pull/1101#discussion_r1915181813
##########
src/Lucene.Net.Tests.AllProjects/Support/ExceptionHandling/TestExceptionExtensions.cs:
##########
@@ -375,6 +377,73 @@ public void
TestIsIllegalArgumentException_TestEnvironment(Type exceptionType, b
}
}
+ private class MyException : Exception
+ {
+ public MyException(string message) : base(message)
+ {
+ }
+ }
+
+ private class MyException2 : Exception
+ {
+ public MyException2(string message) : base(message)
+ {
+ }
+ }
+
+ [Test]
+ public void TestPrintStackTrace()
+ {
+ using var sw = new StringWriter();
+
+ try
+ {
+ throw new MyException("Test exception");
+ }
+ catch (Exception e)
+ {
+ e.PrintStackTrace(sw);
+ }
+
+ var str = sw.ToString();
+
+ Assert.IsTrue(str.Contains(typeof(MyException).FullName ?? throw
new InvalidOperationException("Type name is null")));
+ Assert.IsTrue(str.Contains("Test exception"));
+ Assert.IsTrue(str.Contains(nameof(TestPrintStackTrace)));
+ }
+
+ [Test]
+ public void TestPrintStackTrace_WithSuppressed()
+ {
+ using var sw = new StringWriter();
+
+ try
+ {
+ throw new MyException("Test exception");
+ }
+ catch (Exception e)
+ {
+ try
+ {
+ throw new MyException2("Suppressed exception");
+ }
+ catch (Exception suppressed)
+ {
+ e.AddSuppressed(suppressed);
+ }
+
+ e.PrintStackTrace(sw);
+ }
+
+ var str = sw.ToString();
+
+ Assert.IsTrue(str.Contains(typeof(MyException).FullName ?? throw
new InvalidOperationException("Type name is null")));
+ Assert.IsTrue(str.Contains("Test exception"));
+ Assert.IsTrue(str.Contains(nameof(TestPrintStackTrace)));
+ Assert.IsTrue(str.Contains(typeof(MyException2).FullName ?? throw
new InvalidOperationException("Type name is null")));
Review Comment:
I'll replace with `!`, but note that it can be null in some cases that
aren't relevant here, and so it is a compiler warning:

--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]