If only it were that simple. Even if it was that simple, that still represents a huge cost overhead.
There are times when the even recognizing that the input is improper is extremely hard, if not downright impossible. Some examples:
- Having the compiler determine whether a program halts. First off, there's the halting problem that makes answering this question a bit more than problematic. Secondly, what if the program isn't supposed to halt? Is halting an error? (In many cases, yes it is.)
- Having the compiler determine whether a variable is assigned a value before the variable is accessed. This is equivalent to the halting problem.
- Having a C compiler make sense of i = 5; printf ("%d\n", (i++)*i); The result might be to print 36. Or it might print 25, or 30, or 1234567890. Then it might result in a call reformat_hard_drive() or even eject_nasal_demons(). All are valid responses to such nonsense.
There is no way to anticipate all the goofy ways users can get things wrong. We can try, and trying is a "good thing", but there are no guarantees.