Here is my experience, I hope it matches best practice.
First of all, let me mention that I typically work in situations where I have full control, and won't build my own UI as @tom mentioned. In general, if there is at any point a large probability that your program gets junk inputs it will be worth checking for them.
Some tradeoffs that I typically make to decide whether I should check my inputs:
- Development time vs debug time
- If erronious inputs are hard to debug (for example because they don't cause errors but just undesirable outcomes) the balance will typically be in favor of checking, otherwise not.
- If you are not sure where you will end up (re)using the code, it may help to enforce any assumptions that are required on the input.
- Development time vs runtime experience
- If your code takes an hour to run, and will break in the end when an invalid input value occurs, you would want to check of this at the beginning of the code
- If the code runs into an error whilst opening a file, the user may not understand immediately, if you mention that no valid filename is specified this may be easier to deal with.