diff --git a/core/includes/errors.inc b/core/includes/errors.inc
index 99cab85..33ba3c4 100644
--- a/core/includes/errors.inc
+++ b/core/includes/errors.inc
@@ -223,6 +223,13 @@ function _drupal_log_error($error, $fatal = FALSE) {
         // Generate a backtrace containing only scalar argument values.
         $message .= '<pre class="backtrace">' . Error::formatBacktrace($backtrace) . '</pre>';
       }
+      if (\Drupal::hasService('session')) {
+        // Message display is dependent on sessions being available.
+        drupal_set_message(SafeMarkup::set($message), $class, TRUE);
+      }
+      else {
+        print $message;
+      }
     }
 
     if ($fatal) {
@@ -248,15 +255,6 @@ function _drupal_log_error($error, $fatal = FALSE) {
       // An exception must halt script execution.
       exit;
     }
-    else {
-      if (\Drupal::hasService('session')) {
-        // Message display is dependent on sessions being available.
-        drupal_set_message(SafeMarkup::set($message), $class, TRUE);
-      }
-      else {
-        print $message;
-      }
-    }
   }
 }
 
diff --git a/core/modules/system/src/Tests/System/ErrorHandlerTest.php b/core/modules/system/src/Tests/System/ErrorHandlerTest.php
index 8164f36..bcbf120 100644
--- a/core/modules/system/src/Tests/System/ErrorHandlerTest.php
+++ b/core/modules/system/src/Tests/System/ErrorHandlerTest.php
@@ -65,6 +65,7 @@ function testErrorHandler() {
     $this->assertErrorMessage($error_notice);
     $this->assertErrorMessage($error_warning);
     $this->assertErrorMessage($error_user_notice);
+    $this->assertNoRaw('class="messages messages--"', 'Did not find the messages block');
     $this->assertRaw('<pre class="backtrace">', 'Found pre element with backtrace class.');
 
     // Set error reporting to display verbose notices.
