How can can I get theme callback to work for an error page? I've created a custom error handler for 404 errors (page not found).

I've set up Home » Administration » Configuration » System  » Error Pages for 404 errors to point to http://example.com/myerrorpage, and then I have the following in hook_menu

/**
 * Implements hook_menu().
 */
function MYMODULE_menu() {
  $items = array();
  $items['myerrorpage'] = array(
    'title' =&gt; 'myerrorpage',
    'access callback' =&gt; TRUE,
    'page callback' =&gt; 'myerror_page',
    'theme callback' =&gt; 'myerror_theme',
    'type' =&gt; MENU_CALLBACK,
  );
  return $items;
}


When I enter a non-existing path (e.g. http://example.com/bogus) the page callback is invoked as expected.

However, the theme callback is not.

To get the  theme callback to fire, I need to enter the following path: http://example.com/myerrorpage.

I do not understand why the theme callback does not fire at the same time as the page callback.

Is there any way to get the theme callback (or hook_custom_theme()) to fire when a non-existing path is given?
In menu_get_custom_theme(), you can see that theme callback on menu router would not be called if the menu router doesn't exist. But you can achieve that with hook_custom_theme().

I'll go like this:

/**
 * Implements hook_custom_theme().
 */
function MYMODULE_custom_theme() {
  $router_item = menu_get_item();
  if (empty($router_item)) {
    return 'THEME_NAME';
  }
}