Raising ERRORS in BigQuery

Does anyone have interesting use cases for the ERROR function in BigQuery?
If you like BQ errors so much that you've decided to create your own, or if you're debugging with dirty data, maybe check it out.
If will raise an error that you specify whenever executed. Plus you can also combine it with FORMAT to see what was the value that generated the issue.


SELECT population/surface AS population_density
FROM input_data
WHERE IF(IFNULL(surface,0) > 0,
TRUE,
ERROR(FORMAT('Error: surface must be strictly greater than 0, but is %t', surface)));
The query fails with the error Error: surface must be strictly greater than 0, but is 0.
SELECT population / CASE WHEN IFNULL(surface,0) > 0 THEN surface
ELSE ERROR(FORMAT('Error: surface must be strictly greater than 0, but is %t', surface)) END AS population_density
FROM input_data
The query fails with the error Error: surface must be strictly greater than 0, but is NULL.