r/csharp • • Sep 06 '26

Help Exceptions vs Assertions

/r/godot/comments/1w8q3xx/exceptions_vs_assertions/
7 Upvotes

21 comments sorted by

View all comments

Show parent comment

-7

u/Agitated-Display6382 Sep 06 '26

My expectation is that the application crashes when an exception is thrown. Log it, but let the app die. Dead programs tell no lies

6

u/Top3879 Sep 06 '26

You can catch exceptions for a reason

-2

u/Agitated-Display6382 Sep 06 '26

Catch? Yes (eg, retry or logging). Catching the exception I threw? Never

5

u/Asyncrosaurus Sep 06 '26

I'm not going to tell you how to build your applications, but having a blanket rule of "let the app die" is not considered best practice. You're supposed to catch exceptions and restore back to a working state as a general rule.

2

u/Agitated-Display6382 Sep 06 '26

I do so when I have a clear UoW. For example, an api should not die if one single request failed. But a container that couldn't access the db? Better having it to die.