Skip to content
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

Open
Robertbaelde opened this issue Feb 12, 2017 · 3 comments
Open

Should not enough tickets be an exception? #37

Robertbaelde opened this issue Feb 12, 2017 · 3 comments

Comments

@Robertbaelde
Copy link
Collaborator

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.

@paulredmond
Copy link
Collaborator

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.

@mabadir
Copy link
Collaborator

mabadir commented Feb 12, 2017

It can be considered an exception because it will stop the normal flow of your request (i.e. creating order).
Plus, it's very good example, because now you can catch it and act accordingly.

@roni-estein
Copy link
Collaborator

roni-estein commented Feb 12, 2017

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants