getShardsForQuery may throw exception with uassert, but write command should not throw. Add try catch around the call.