[core] Better exception handling.