3 ms·
The runtime error can still occur... just in a different location and obscured by useless abstractions and code surrounding it. One point of a type such as Ema
by tuukkah 9y ago
The runtime error can still occur... just in a different location and obscured by useless abstractions and code surrounding it.
One point of a type such as EmailAddress is that the validation is invoked at one place (inside the constructor) as opposed to an invocation at every usage site like send_email, which is a lot of work and error prone.
Another point is that when validation fails you get the runtime exception with a useful stack trace: instead of "address X was not valid when trying to send email" you actually get "you tried to convert string X to email address but it's not valid". In the first case all you can do is fail to send the message, but in the second case you can ask the user again, fix your escaping code etc.