diff --git a/core/lib/Drupal/Core/Routing/RouteProvider.php b/core/lib/Drupal/Core/Routing/RouteProvider.php
index be647e1..dcfb39b 100644
--- a/core/lib/Drupal/Core/Routing/RouteProvider.php
+++ b/core/lib/Drupal/Core/Routing/RouteProvider.php
@@ -212,13 +212,13 @@ public function preLoadRoutes($names) {
       else {
         try {
           $result = $this->connection->query('SELECT name, route FROM {' . $this->connection->escapeTable($this->tableName) . '} WHERE name IN ( :names[] )', array(':names[]' => $routes_to_load));
+          $routes = $result->fetchAllKeyed();
+
+          $this->cache->set($cid, $routes, Cache::PERMANENT, ['routes']);
         }
         catch (\Exception $e) {
-          $result = [];
+          $routes = [];
         }
-        $routes = $result->fetchAllKeyed();
-
-        $this->cache->set($cid, $routes, Cache::PERMANENT, ['routes']);
       }
 
       $this->serializedRoutes += $routes;
