-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Should not enough tickets be an exception? #37
Comments
I view this example is this way: if you don't use an exception, how would you design it instead? In this case you might return a boolean false early perhaps, and then your client code would then be responsible for checking type and provide a few if/else checks to respond to your code. To me that would feel more clunky. I think one good approach is try out a couple logical flows/ways of doing it (try writing the code with an exception, then change to without) and see which one feels more natural. In this case I would personally reach for an exception, and the controller is very readable when this exception is triggered vs hunting down a boolean false, etc. I think the best answer for exception/not is trying it out yourself and experimenting. |
It can be considered an exception because it will stop the normal flow of your request (i.e. creating order). |
Not arguing a good example or anyones code choices, also I'm old. But I've always also used exceptions for "exceptional" circumstances. I haven't thought about this for a long time so the information may be dated but exception handling "was" a much more CPU memory costly event. It had and has many uses but there was a reason it wasn't used in a normal program flow and reserved its own memory state the good old try catch. |
Hi Adam,
First of all, great course! learning a lot of new stuff.
I was wondering, in lesson 3.3 (2ccc635) we throw an exception when there are not enough tickets left.
Isn't this a bad use case for exceptions? Since it is not really exceptional, concerts do sell out.
Wondering what your and others views are on this topic.
The text was updated successfully, but these errors were encountered: