Catch common exceptions so we can log rather than crash.