This is an interview question, it has been done.
Which of the following circumstances should throw Exceptions? Explain your reasoning.
(1) Someone tries to set the capacity of a PackingBox to a negative value.
(2) A syntax error is found in a configuration file that an object uses to set its initial state.
(3)A method that searches for a programmer-specified word in a string array cannot find any occurrence of the word.
from When and how should I use exception handling?
" But if you get some invalid data from inside your very own program - don't throw an exception. If your problem comes from your own bad code, it's better to use ASSERTs to guard against it. Exception handling is needed to identify problems that program cannot handle and tell them about the user, because user can handle them. "
I think : (1) should use exception, because the input is from users. The error is not generated from the inside of the program.
(2) and (3) should not use exceptions because they are from the the inside of the program. And, the users cannot help that. So, we should use "assert" or "if" branch to handle the errors by the program itself.
Right ?
Any help is appreciated.
thanks !