Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy are Exceptions said to be so bad for Input Validation?
    primarykey
    data
    text
    <p>I understand that "Exceptions are for exceptional cases" [a], but besides just being repeated <a href="https://stackoverflow.com/questions/88541/business-objects-validation-and-exceptions#88917">over</a> and <a href="https://stackoverflow.com/questions/77127/when-to-throw-an-exception#77227">over</a> again, I've never found an actual reason for this fact.</p> <p>Being that they halt execution, it makes sense that you wouldn't want them for plain conditional logic, but why not input validation?</p> <p>Say you were to loop through a group of inputs and catch each exception to group them together for user notification... I continually see that this is somehow "wrong" because users enter incorrect input all the time, but that point seems to be <a href="https://stackoverflow.com/questions/77127/when-to-throw-an-exception#77164">based on semantics</a>. </p> <p>The input is Not what was expected and hence is exceptional. Throwing an exception allows me to define exactly what was wrong like StringValueTooLong or or IntegerValueTooLow or InvalidDateValue or whatever. Why is this considered wrong?</p> <p>Alternatives to throwing an exception would be to either return (and eventually collect) an error code or far worse an error string. Then I would either show those error strings directly, or parse the error codes and then show corresponding error messages to the user. Wouldn't a exception be considered a malleable error code? Why create a separate table of error codes and messages, when these could be generalized with the exception functionality already built into my language?</p> <p>Also, I <a href="http://www.martinfowler.com/eaaDev/Notification.html" rel="noreferrer">found this article by Martin Fowler</a> as to how to handle such things - the Notification pattern. I'm not sure how I see this as being anything other than Exceptions that don't halt execution. </p> <p>a: Everywhere I've read anything about Exceptions.</p> <p>--- Edit ---</p> <p>Many great points have been made. I've commented on most and +'d the good points, but I'm not yet completely convinced.</p> <p>I don't mean to advocate Exceptions as the proper means to resolve Input Validation, but I would like to find good reasons why the practice is considered so evil when it seems most alternate solutions are just Exceptions in disguise.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    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