© 2026 Hedgehog Software, LLC
Twitter
GitHub
Discord
System
Light
Dark
More
Communities
Docs
About
Terms
Privacy
Search
Star
Feedback
Setup for Free
C
C#
•
2mo ago
•
2 replies
Ruttie
Exceptions in finalizer
intermediate
I want to run some debug assertions to check if an object was disposed properly by checking state
.
The easiest way I can see to do so is in the finalizer
.
I would have something like this
:
#if DEBUG
~MyClass() {
Debug.Assert(condition);
}
#endif
#if DEBUG
~MyClass() {
Debug.Assert(condition);
}
#endif
My question is
, is it safe to throw exceptions in finalizers
?
Should I be worried about the GC ending up in a weird state
?
C#
Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871
Members
View on Discord
Resources
ModelContextProtocol
ModelContextProtocol
MCP Server
Similar Threads
Was this page helpful?
Yes
No
Recent Announcements
Similar Threads
Exceptions.
C
C# / help
17mo ago
✅ Exceptions
C
C# / help
2y ago
✅ MediatR exceptions
C
C# / help
3y ago
❔ Utf8JsonReader.GetString exceptions
C
C# / help
3y ago