Try to catch exceptions better to avoid dumping out.