From 3c602c59a8ba2fa31d8a54365ed58e9dd602af53 Mon Sep 17 00:00:00 2001 From: Shad Storhaug Date: Tue, 6 Apr 2021 20:58:36 +0700 Subject: [PATCH] SWEEP: Reviewed all catch blocks where Lucene uses Error and converted them to use our IsError() extension method (see #446). --- .../Standard/Parser/StandardSyntaxParser.cs | 2 +- .../Search/TestDisjunctionMaxQuery.cs | 16 ++++++++-------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/Lucene.Net.QueryParser/Flexible/Standard/Parser/StandardSyntaxParser.cs b/src/Lucene.Net.QueryParser/Flexible/Standard/Parser/StandardSyntaxParser.cs index f060ca52c6..1ff425c1da 100644 --- a/src/Lucene.Net.QueryParser/Flexible/Standard/Parser/StandardSyntaxParser.cs +++ b/src/Lucene.Net.QueryParser/Flexible/Standard/Parser/StandardSyntaxParser.cs @@ -72,7 +72,7 @@ public IQueryNode Parse(string query, string field) tme.SetQuery(query); throw tme; } - catch (Exception tme) + catch (Exception tme) when (tme.IsError()) { IMessage message = new Message(QueryParserMessages.INVALID_SYNTAX_CANNOT_PARSE, query, tme.Message); QueryNodeParseException e = new QueryNodeParseException(tme); diff --git a/src/Lucene.Net.Tests/Search/TestDisjunctionMaxQuery.cs b/src/Lucene.Net.Tests/Search/TestDisjunctionMaxQuery.cs index feb6cf6278..77608980a9 100644 --- a/src/Lucene.Net.Tests/Search/TestDisjunctionMaxQuery.cs +++ b/src/Lucene.Net.Tests/Search/TestDisjunctionMaxQuery.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Globalization; using Lucene.Net.Documents; using Lucene.Net.Index.Extensions; @@ -245,7 +245,7 @@ public virtual void TestSimpleEqualScores1() Assert.AreEqual(score, h[i].Score, SCORE_COMP_THRESH, "score #" + i + " is not the same"); } } - catch (Exception /*e*/) + catch (Exception e) when (e.IsError()) { PrintHits("testSimpleEqualScores1", h, s); throw; // LUCENENET: CA2200: Rethrow to preserve stack details (https://docs.microsoft.com/en-us/visualstudio/code-quality/ca2200-rethrow-to-preserve-stack-details) @@ -275,7 +275,7 @@ public virtual void TestSimpleEqualScores2() Assert.AreEqual(score, h[i].Score, SCORE_COMP_THRESH, "score #" + i + " is not the same"); } } - catch (Exception /*e*/) + catch (Exception e) when (e.IsError()) { PrintHits("testSimpleEqualScores2", h, s); throw; // LUCENENET: CA2200: Rethrow to preserve stack details (https://docs.microsoft.com/en-us/visualstudio/code-quality/ca2200-rethrow-to-preserve-stack-details) @@ -307,7 +307,7 @@ public virtual void TestSimpleEqualScores3() Assert.AreEqual(score, h[i].Score, SCORE_COMP_THRESH, "score #" + i + " is not the same"); } } - catch (Exception /*e*/) + catch (Exception e) when (e.IsError()) { PrintHits("testSimpleEqualScores3", h, s); throw; // LUCENENET: CA2200: Rethrow to preserve stack details (https://docs.microsoft.com/en-us/visualstudio/code-quality/ca2200-rethrow-to-preserve-stack-details) @@ -338,7 +338,7 @@ public virtual void TestSimpleTiebreaker() Assert.IsTrue(score0 > score1, "d2 does not have better score then others: " + score0 + " >? " + score1); Assert.AreEqual(score1, score2, SCORE_COMP_THRESH, "d4 and d1 don't have equal scores"); } - catch (Exception /*e*/) + catch (Exception e) when (e.IsError()) { PrintHits("testSimpleTiebreaker", h, s); throw; // LUCENENET: CA2200: Rethrow to preserve stack details (https://docs.microsoft.com/en-us/visualstudio/code-quality/ca2200-rethrow-to-preserve-stack-details) @@ -389,7 +389,7 @@ public virtual void TestBooleanRequiredEqualScores() Assert.AreEqual(score, h[i].Score, SCORE_COMP_THRESH, "score #" + i + " is not the same"); } } - catch (Exception /*e*/) + catch (Exception e) when (e.IsError()) { PrintHits("testBooleanRequiredEqualScores1", h, s); throw; // LUCENENET: CA2200: Rethrow to preserve stack details (https://docs.microsoft.com/en-us/visualstudio/code-quality/ca2200-rethrow-to-preserve-stack-details) @@ -432,7 +432,7 @@ public virtual void TestBooleanOptionalNoTiebreaker() float score1 = h[h.Length - 1].Score; Assert.IsTrue(score > score1, "d1 does not have worse score then others: " + score + " >? " + score1); } - catch (Exception /*e*/) + catch (Exception e) when (e.IsError()) { PrintHits("testBooleanOptionalNoTiebreaker", h, s); throw; // LUCENENET: CA2200: Rethrow to preserve stack details (https://docs.microsoft.com/en-us/visualstudio/code-quality/ca2200-rethrow-to-preserve-stack-details) @@ -486,7 +486,7 @@ public virtual void TestBooleanOptionalWithTiebreaker() Assert.AreEqual("d1", doc3, "wrong fourth"); Assert.IsTrue(score2 > score3, "d1 does not have worse score then d3: " + score2 + " >? " + score3); } - catch (Exception /*e*/) + catch (Exception e) when (e.IsError()) { PrintHits("testBooleanOptionalWithTiebreaker", h, s); throw; // LUCENENET: CA2200: Rethrow to preserve stack details (https://docs.microsoft.com/en-us/visualstudio/code-quality/ca2200-rethrow-to-preserve-stack-details)