If you want to return an error message, just:

$error="it broke!"

etc

set $error="" at the beginning of the UDF if you want to default to working etc...