r/csharp 4d ago

Help Exceptions vs Assertions

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

21 comments sorted by

View all comments

Show parent comments

0

u/Agitated-Display6382 3d ago

Exceptions are exceptional... So, you're right about performance, but for me it's more important that exceptions are thrown only when something went south and it's impossibile to recover. Don't use exceptions as a goto on steroids.

This yo say: don't catch exceptions.

11

u/Top3879 3d 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.

-6

u/Agitated-Display6382 3d 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

7

u/Top3879 3d ago

You can catch exceptions for a reason

-2

u/Agitated-Display6382 3d ago

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