Skip to content

Commit 8c84bb0

Browse files
committed
Improve rethrows in parsing stages
ExceptionDispatchInfo allows to rethrow the original exception from a reference to the exception without altering the call stack info.
1 parent b85e385 commit 8c84bb0

File tree

3 files changed

+6
-3
lines changed

3 files changed

+6
-3
lines changed

Rubberduck.Parsing/VBA/DeclarationResolving/DeclarationResolveRunner.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using System.Collections.Generic;
33
using System.Linq;
4+
using System.Runtime.ExceptionServices;
45
using System.Threading;
56
using System.Threading.Tasks;
67
using Rubberduck.Parsing.Common;
@@ -55,7 +56,7 @@ protected override void ResolveDeclarations(IReadOnlyCollection<QualifiedModuleN
5556
{
5657
if (exception.Flatten().InnerExceptions.All(ex => ex is OperationCanceledException))
5758
{
58-
throw exception.InnerException ?? exception; //This eliminates the stack trace, but for the cancellation, this is irrelevant.
59+
ExceptionDispatchInfo.Capture(exception.InnerException ?? exception).Throw();
5960
}
6061
_parserStateManager.SetStatusAndFireStateChanged(this, ParserState.ResolverError, token);
6162
throw;

Rubberduck.Parsing/VBA/Parsing/ParseRunner.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using System.Collections.Generic;
33
using System.Linq;
4+
using System.Runtime.ExceptionServices;
45
using System.Threading;
56
using System.Threading.Tasks;
67
using Rubberduck.VBEditor;
@@ -61,7 +62,7 @@ public ParseRunner(
6162
{
6263
if (exception.Flatten().InnerExceptions.All(ex => ex is OperationCanceledException))
6364
{
64-
throw exception.InnerException ?? exception; //This eliminates the stack trace, but for the cancellation, this is irrelevant.
65+
ExceptionDispatchInfo.Capture(exception.InnerException ?? exception).Throw();
6566
}
6667
StateManager.SetStatusAndFireStateChanged(this, ParserState.Error, token);
6768
throw;

Rubberduck.Parsing/VBA/ReferenceManagement/ReferenceResolveRunner.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using System.Collections.Generic;
33
using System.Linq;
4+
using System.Runtime.ExceptionServices;
45
using System.Threading;
56
using System.Threading.Tasks;
67
using Antlr4.Runtime.Tree;
@@ -41,7 +42,7 @@ protected override void ResolveReferences(ICollection<KeyValuePair<QualifiedModu
4142
{
4243
if (exception.Flatten().InnerExceptions.All(ex => ex is OperationCanceledException))
4344
{
44-
throw exception.InnerException ?? exception; //This eliminates the stack trace, but for the cancellation, this is irrelevant.
45+
ExceptionDispatchInfo.Capture(exception.InnerException ?? exception).Throw();
4546
}
4647

4748
_parserStateManager.SetStatusAndFireStateChanged(this, ParserState.ResolverError, token);

0 commit comments

Comments
 (0)