In our application we're going to be allowing users to type in arithmetic expressions (+ - * /) using other database columns for numbers, which would then be parsed by the application and written into the database as a computed column.
However there are problems that arise with allowing users to create expressions that could cause exceptions when you select *
the table, such as divide-by-zero, arithmetic-overflow, and possible others I haven't come across yet (though I think that's all of them).
Having the database throw an exception on select *
would be absolutely devastating. I would rather try to rewrite their expression into something that would fail gracefully if they have error-prone data.
For divide-by-zero the solution is pretty straightforward:
add [Col] as case {divisor} when 0 then N'DIVIDE-BY-ZERO' else {expression} end
My question is what can I do for arithmetic overflow? Showing bunk or obviously wrong data in the column would not be a problem, but throwing exceptions would.