Add exception handling.

Make sure to exit with non-zero status on every exception