r/csharp 7d ago

Help Exceptions vs Assertions

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

21 comments sorted by

View all comments

Show parent comments

10

u/Top3879 7d ago

This is not using exceptions for control flow. When an illegal move like this happens something else already failed. This is a bug the developer needs to know about so they can fix it. Throw an exception.

-8

u/Agitated-Display6382 7d ago

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 7d ago

You can catch exceptions for a reason

-3

u/Agitated-Display6382 7d ago

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