Skip to content

Commit b2b04ee

Browse files
CopilotYunchuWang
andcommitted
Improve exception handling in CompositeDisposable.Dispose
Co-authored-by: YunchuWang <[email protected]>
1 parent 2429a1f commit b2b04ee

File tree

1 file changed

+29
-2
lines changed

1 file changed

+29
-2
lines changed

src/Worker/Grpc/DualCategoryLogger.cs

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,35 @@ public CompositeDisposable(IDisposable first, IDisposable second)
8686

8787
public void Dispose()
8888
{
89-
this.first.Dispose();
90-
this.second.Dispose();
89+
Exception? firstException = null;
90+
91+
try
92+
{
93+
this.first.Dispose();
94+
}
95+
catch (Exception ex)
96+
{
97+
firstException = ex;
98+
}
99+
100+
try
101+
{
102+
this.second.Dispose();
103+
}
104+
catch (Exception ex)
105+
{
106+
if (firstException is null)
107+
{
108+
throw;
109+
}
110+
111+
throw new AggregateException(firstException, ex);
112+
}
113+
114+
if (firstException is not null)
115+
{
116+
throw firstException;
117+
}
91118
}
92119
}
93120
}

0 commit comments

Comments
 (0)