public function __construct(
  string $message,
  int $op = MCRouter::mc_op_unknown,
  int $reply = MCRouter::mc_res_unknown,
  string $key = '',


  • string $message
  • int $op = MCRouter::mc_op_unknown
  • int $reply = MCRouter::mc_res_unknown
  • string $key = ''


You normally will catch a MCRouterException over constructing one explicitly, but it can be done. Here is an example where you can check the version of the memcached server and throw if you don't have the right one.

async function simple_mcrouter(): Awaitable<void> {
  $servers = Vector {\getenv('HHVM_TEST_MCROUTER')};
  $mc = \MCRouter::createSimple($servers);
  $ver = await $mc->version();
  if (\strpos($ver, "100.100") === false) {
    throw new \MCRouterException(
      "The version of memcached is not right",

async function run(): Awaitable<void> {
  try {
    await simple_mcrouter();
  } catch (\MCRouterException $ex) {
string(37) "The version of memcached is not right"