Should the maintenance template be used when the database API raises an exception? I have created a maintenance-page.html.twig template for my site.

The settings.php file says: 


  This applies when the site is explicitly set to maintenance mode through the administration page or when the database is inactive due to an error.


However, on my site, this only works if I explicitly turn on maintenance mode. If I intentionally break access to my database by changing the password I get a page with a PDO error, not my maintenance page.

Is this a bug, or am I missing something?
This looks to be the case of where the documentation is out-of-date. That comment has been around verbatim since D7. D8 doesn't produce a themed maintenance page like D7.

When looking at _drupal_log_error(), you can see that unless Drupal is going through the install process, a fatal error will output a bare error message with a 500 status then exit:

if ($fatal) {
  // We fallback to a maintenance page at this point, because the page generation
  // itself can generate errors.
  // Should not translate the string to avoid errors producing more errors.
  $message = 'The website encountered an unexpected error. Please try again later.' . '&lt;br /&gt;' . $message;

  if ($is_installer) {
    // install_display_output() prints the output and ends script execution.
    $output = array(
      '#title' =&gt; 'Error',
      '#markup' =&gt; $message,
    );
    install_display_output($output, $GLOBALS['install_state'], $response-&gt;headers-&gt;all());
    exit;
  }

  $response-&gt;setContent($message);
  $response-&gt;setStatusCode(500, '500 Service unavailable (with message)');

  $response-&gt;send();
  // An exception must halt script execution.
  exit;
}


Whereas in D7, _drupal_log_error() passes through a themed maintenance page:

if ($fatal) {
  drupal_set_title(t('Error'));
  // We fallback to a maintenance page at this point, because the page generation
  // itself can generate errors.
  print theme('maintenance_page', array('content' =&gt; t('The website encountered an unexpected error. Please try again later.')));
  exit;
}