I'm reading The Pragmatic Programmer and in the section Assertive programming the authors say:
Don’t use assertions in place of real error handling. Assertions check for things that should never happen: you don’t want to be writing code such as the following:
puts("Enter 'Y' or 'N': ")
ans = gets[0] # Grab first character of response
assert((ch == 'Y') || (ch == 'N')) # Very bad idea!
I'm expecting only two values (either Y/N) and if it received some other input, I would want to assert it and throw an error. I want to understand why the assert approach is wrong and what would be a better approach?