Catch error when no records found

Catch error when no records found

Currently if I have the code below:
u = users[name == input.name]


The form just goes into an endless loop if there is no such record fulfilling the criterion name == input.name. Is there anyway to catch this and generate some kind of error message instead of an endlessly loading form?