Note that there are some explanatory texts on larger screens.

plurals
  1. POIs it normal to use many business exceptions if needed?
    primarykey
    data
    text
    <p>Is it a good practice to define and throw custom exceptions even if the application needs lots of them?</p> <ul> <li>EntityNotFoundException</li> <li>EntityAlreadyExistsException</li> <li>EntityNotUniqueException</li> <li>EntityNotAddedException</li> <li>EntityNotUpdatedException</li> <li>EntityNotDeletedException</li> <li>QuizOverException</li> <li>QuizExpiredException</li> <li>TableAlreadyBookedException</li> <li>EndDateMustBeGreaterThanStartDateException</li> </ul> <p>I tried to name these sample exception names to describe their purpose as good as I could. I hope they could form an idea of what I am trying to ask.</p> <p>Don't limit your imagination with only these exceptions but all that could arise during you application's life. Consider both CRUD and business exceptions.</p> <p>I know that throwing and catching exceptions is an expensive process in terms of performance but don't they provide a more elegant way to develop you app?</p> <ul> <li>Isn't it better to throw a <code>EntityNotFoundException</code> instead of writing an if statement to check whether the entity is null?</li> <li>Isn't it better to throw a <code>EntityAlreadyExistsException</code> instead of writing an additional if statement which will call a method to check whether the entity with the given Id already exists?</li> <li>Isn't it better to throw a <code>EntityNotAddedException</code> instead of checking the return value of type bool specifying whether the transaction was successful or not? What if we want to return an object?</li> </ul> <p>I feel that the answer will be like "you should not use <code>EntityNotFoundException</code> but instead check if null, but you should use <code>EntityAlreadyExistsException</code>", "there is no holy grail".</p> <p>I am wondering what is the elegant way of doing this?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload