Replace some sys.errors with proper exceptions.

Just got bit by a bug where I was catching `ArithmeticException`s in, eg, `log`, but some types where throwing `RuntimeException`s (via `sys.error`). Replaced a bunch of `sys.error`s with real exceptions.