diff --git a/core/ExceptionHandler.php b/core/ExceptionHandler.php
index b1a8a408db1adb583de2d7d5aa5d0b8e503ac528..f636b3b05d715e4d441dee131acb66ba0bd22423 100644
--- a/core/ExceptionHandler.php
+++ b/core/ExceptionHandler.php
@@ -25,7 +25,7 @@ class ExceptionHandler
     }
 
     /**
-     * @param Exception $exception
+     * @param Exception|\Throwable $exception
      */
     public static function handleException($exception)
     {
@@ -37,7 +37,7 @@ class ExceptionHandler
     }
 
     /**
-     * @param Exception $exception
+     * @param Exception|\Throwable $exception
      */
     public static function dieWithCliError($exception)
     {
@@ -61,7 +61,7 @@ class ExceptionHandler
     }
 
     /**
-     * @param Exception $exception
+     * @param Exception|\Throwable $exception
      */
     public static function dieWithHtmlErrorPage($exception)
     {
@@ -73,7 +73,7 @@ class ExceptionHandler
     }
 
     /**
-     * @param Exception $ex
+     * @param Exception|\Throwable $ex
      */
     private static function getErrorResponse($ex)
     {
diff --git a/core/Plugin/Dimension/VisitDimension.php b/core/Plugin/Dimension/VisitDimension.php
index 6932161d1b5612915a3eec50ef70e99ea9f98d4f..3f258da481af42d0861c94a28d42e65d24280198 100644
--- a/core/Plugin/Dimension/VisitDimension.php
+++ b/core/Plugin/Dimension/VisitDimension.php
@@ -354,7 +354,15 @@ abstract class VisitDimension extends Dimension
             }
         }
 
+        $count = 0;
         while (count($dimensions) > 0) {
+            $count++;
+            if ($count > 1000) {
+                foreach ($dimensions as $dimension) {
+                    $sorted[] = $dimension;
+                }
+                break; // to prevent an endless loop
+            }
             foreach ($dimensions as $key => $dimension) {
                 $fields = $depenencies[$dimension->getColumnName()];
                 if (count(array_intersect($fields, $exists)) === count($fields)) {