Of course it can notify of the problem with an error message in the log or some other mechanism.
To put it in a more abstract way, my approach is Other developers, among them some colleagues of mine, use another strategy. They assume that a piece of code should be given correct input and it should not be responsible for what happens if the input is wrong.
Regular Expression Regular Expressions are specially formatted strings for specifying patterns in text.
They can be useful during information validation, to ensure that data is in a specified format.
Requiring the caller to validate arguments can result in faster code because the caller may understand certain invariants that prevent invalid values from being passed.
If there are no empty fields then the following code validates the first name by calling the static method Match of the Regex class, passing both the string to validate and the Regular Expression as arguments. This object contains a Success property that indicates whether a method Match's first argument matches the pattern specified by the Regular Expression in the second argument.
I am not sure if assertions are enough, if they are switched off in a production system: maybe some situation will occur in production that had not occured during testing.
Anyway, I was really surprised that many people follow the opposite approach: they let the application crash "on-purpose" because they maintain that this will make it easier to find bugs during testing. Berkeley, we were told that a good program is 50% error handling. "What if the inputs are invalid but the program does not crash?
Summarizing Which of the two approaches to handling wrong input would you advise? So my approach is to never assume a method is passed correct input. In a production system it would just write some information to the log.
Also, I would use a mechanism to catch the problem and notify about it. I do not think that extra checks can lead to performance problems.