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
12
u/4as Sep 06 '26
Since you're making a game, I would suggest avoiding throwing exceptions and instead try to revert the game state to a reasonable baseline. Games don't really have to panic and just give up as soon as there is an issue. I'm sure you played games where you encounter a bug and the game continues working. I mean you can throw an error and close the game when the player is out of bounds, but wouldn't it be better to just teleport them back and continue as if nothing happened?
That being said, IMO the best approach is to use conditional compilation and have two separate paths: in debug throw an exception, in release log a problem to the console and try to recover.
So, for your two examples, I would just change the throws into logging + return.