Catch exception when running a command.