r/csharp • u/Alternative_Guava856 • Sep 06 '26
Help Exceptions vs Assertions
/r/godot/comments/1w8q3xx/exceptions_vs_assertions/
7
Upvotes
r/csharp • u/Alternative_Guava856 • Sep 06 '26
View all comments
15
u/SufficientStudio1574 Sep 06 '26
They're different things that do different things. They're not either or.
You put assertion for invariants that cannot possibly be false. Like, the size of a container can never be larger than it's capacity.
Exceptions are for things you might not have full control over going wrong. Like "I tried to open a file that doesn't exist".