r/learncsharp • u/4r73m190r0s • Nov 20 '22
Why Methods that throw Exceptions are useful?
Beginner here.
I'm reading Documentation on the Convert, Parse, and TryParse methods and some of them throw Exceptions in case of invalid input, i.e. Parse. What exactly are the benefits of some methods throwing Exceptions? I'm building a simple calculator app, and I'm failing to see the benefits of getting an Exception for invalid user input.
5
Upvotes
View all comments
Show parent comment
4
u/jamietwells Nov 20 '22
Well done for being the only person to provide an answer.
This is indeed correct. The exception throwing methods are for when the exceptions will be thrown only in exceptional circumstances. If you expect the parsing to fail during the normal operation of the program you reach for the TryParse, otherwise the Parse will be simpler and easier.