From 929c02c7fc6b4d0740f823e5a3a876d01fb9a081 Mon Sep 17 00:00:00 2001
From: Mathias Brodala <mbrodala@pagemachine.de>
Date: Mon, 7 Aug 2017 12:50:16 +0200
Subject: [PATCH] [BUGFIX] Let all toplevel exceptions extend the core
 exception

This is a small step to unify exception handling in TYPO3 by
ensuring no internal and 3rd party code is forced to catch the
toplevel PHP exception.

This change e.g. actually allows the FormPagePreviewRenderer to
handle form loading errors.

Resolves: #82052
Releases: master, 8.7
Change-Id: I5cb0b8f2c56a6bbbecc34d87474d6d8b3ad2015c
Reviewed-on: https://review.typo3.org/53651
Reviewed-by: Wolfgang Klinger <wolfgang@wazum.com>
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Mathias Schreiber <mathias.schreiber@typo3.com>
Tested-by: Mathias Schreiber <mathias.schreiber@typo3.com>
Reviewed-by: Joerg Boesche <typo3@joergboesche.de>
Tested-by: Joerg Boesche <typo3@joergboesche.de>
Reviewed-by: Susanne Moog <susanne.moog@typo3.org>
Tested-by: Susanne Moog <susanne.moog@typo3.org>
---
 typo3/sysext/backend/Classes/Exception.php    |  6 +++--
 typo3/sysext/beuser/Classes/Exception.php     |  4 +++-
 .../documentation/Classes/Exception.php       | 24 +++++++++++++++++++
 .../Classes/Exception/Document.php            |  4 +++-
 .../Classes/Exception/XmlParser.php           |  4 +++-
 typo3/sysext/extbase/Classes/Exception.php    |  4 +++-
 .../extensionmanager/Classes/Exception.php    | 24 +++++++++++++++++++
 .../Exception/ExtensionManagerException.php   |  4 +++-
 typo3/sysext/form/Classes/Exception.php       |  4 +++-
 typo3/sysext/frontend/Classes/Exception.php   |  6 +++--
 typo3/sysext/install/Classes/Exception.php    |  6 +++--
 typo3/sysext/lang/Classes/Exception.php       | 24 +++++++++++++++++++
 .../lang/Classes/Exception/Language.php       |  4 +++-
 typo3/sysext/lang/Classes/Exception/Ter.php   |  4 +++-
 .../lang/Classes/Exception/XmlParser.php      |  4 +++-
 15 files changed, 111 insertions(+), 15 deletions(-)
 create mode 100644 typo3/sysext/documentation/Classes/Exception.php
 create mode 100644 typo3/sysext/extensionmanager/Classes/Exception.php
 create mode 100644 typo3/sysext/lang/Classes/Exception.php

diff --git a/typo3/sysext/backend/Classes/Exception.php b/typo3/sysext/backend/Classes/Exception.php
index c7071bec437c..e238115b5814 100644
--- a/typo3/sysext/backend/Classes/Exception.php
+++ b/typo3/sysext/backend/Classes/Exception.php
@@ -14,9 +14,11 @@ namespace TYPO3\CMS\Backend;
  * The TYPO3 project - inspiring people to share!
  */
 
+use TYPO3\CMS\Core\Exception as CoreException;
+
 /**
- * Generic backend exception
+ * Generic Backend exception
  */
-class Exception extends \Exception
+class Exception extends CoreException
 {
 }
diff --git a/typo3/sysext/beuser/Classes/Exception.php b/typo3/sysext/beuser/Classes/Exception.php
index 7f1fd24b1e7a..9155c33bb117 100644
--- a/typo3/sysext/beuser/Classes/Exception.php
+++ b/typo3/sysext/beuser/Classes/Exception.php
@@ -14,9 +14,11 @@ namespace TYPO3\CMS\Beuser;
  * The TYPO3 project - inspiring people to share!
  */
 
+use TYPO3\CMS\Core\Exception as CoreException;
+
 /**
  * Generic Beuser exception
  */
-class Exception extends \Exception
+class Exception extends CoreException
 {
 }
diff --git a/typo3/sysext/documentation/Classes/Exception.php b/typo3/sysext/documentation/Classes/Exception.php
new file mode 100644
index 000000000000..54e47ed70523
--- /dev/null
+++ b/typo3/sysext/documentation/Classes/Exception.php
@@ -0,0 +1,24 @@
+<?php
+namespace TYPO3\CMS\Documentation;
+
+/*
+ * This file is part of the TYPO3 CMS project.
+ *
+ * It is free software; you can redistribute it and/or modify it under
+ * the terms of the GNU General Public License, either version 2
+ * of the License, or any later version.
+ *
+ * For the full copyright and license information, please read the
+ * LICENSE.txt file that was distributed with this source code.
+ *
+ * The TYPO3 project - inspiring people to share!
+ */
+
+use TYPO3\CMS\Core\Exception as CoreException;
+
+/**
+ * Generic Documentation exception
+ */
+class Exception extends CoreException
+{
+}
diff --git a/typo3/sysext/documentation/Classes/Exception/Document.php b/typo3/sysext/documentation/Classes/Exception/Document.php
index ce3957b88707..8027847b0d56 100644
--- a/typo3/sysext/documentation/Classes/Exception/Document.php
+++ b/typo3/sysext/documentation/Classes/Exception/Document.php
@@ -14,9 +14,11 @@ namespace TYPO3\CMS\Documentation\Exception;
  * The TYPO3 project - inspiring people to share!
  */
 
+use TYPO3\CMS\Documentation\Exception;
+
 /**
  * An exception when something is wrong within the document
  */
-class Document extends \TYPO3\CMS\Core\Exception
+class Document extends Exception
 {
 }
diff --git a/typo3/sysext/documentation/Classes/Exception/XmlParser.php b/typo3/sysext/documentation/Classes/Exception/XmlParser.php
index ef193edc20ca..2654c22048c5 100644
--- a/typo3/sysext/documentation/Classes/Exception/XmlParser.php
+++ b/typo3/sysext/documentation/Classes/Exception/XmlParser.php
@@ -14,9 +14,11 @@ namespace TYPO3\CMS\Documentation\Exception;
  * The TYPO3 project - inspiring people to share!
  */
 
+use TYPO3\CMS\Documentation\Exception;
+
 /**
  * An exception when something is wrong within an XML file
  */
-class XmlParser extends \TYPO3\CMS\Core\Exception
+class XmlParser extends Exception
 {
 }
diff --git a/typo3/sysext/extbase/Classes/Exception.php b/typo3/sysext/extbase/Classes/Exception.php
index ff98b7c43606..2f07c1f309e0 100644
--- a/typo3/sysext/extbase/Classes/Exception.php
+++ b/typo3/sysext/extbase/Classes/Exception.php
@@ -14,9 +14,11 @@ namespace TYPO3\CMS\Extbase;
  * The TYPO3 project - inspiring people to share!
  */
 
+use TYPO3\CMS\Core\Exception as CoreException;
+
 /**
  * A generic Extbase exception
  */
-class Exception extends \Exception
+class Exception extends CoreException
 {
 }
diff --git a/typo3/sysext/extensionmanager/Classes/Exception.php b/typo3/sysext/extensionmanager/Classes/Exception.php
new file mode 100644
index 000000000000..0633fb0c75ce
--- /dev/null
+++ b/typo3/sysext/extensionmanager/Classes/Exception.php
@@ -0,0 +1,24 @@
+<?php
+namespace TYPO3\CMS\Extensionmanager;
+
+/*
+ * This file is part of the TYPO3 CMS project.
+ *
+ * It is free software; you can redistribute it and/or modify it under
+ * the terms of the GNU General Public License, either version 2
+ * of the License, or any later version.
+ *
+ * For the full copyright and license information, please read the
+ * LICENSE.txt file that was distributed with this source code.
+ *
+ * The TYPO3 project - inspiring people to share!
+ */
+
+use TYPO3\CMS\Core\Exception as CoreException;
+
+/**
+ * A generic Extensionmanager exception
+ */
+class Exception extends CoreException
+{
+}
diff --git a/typo3/sysext/extensionmanager/Classes/Exception/ExtensionManagerException.php b/typo3/sysext/extensionmanager/Classes/Exception/ExtensionManagerException.php
index 258c0b12bb90..aa0a2de91561 100644
--- a/typo3/sysext/extensionmanager/Classes/Exception/ExtensionManagerException.php
+++ b/typo3/sysext/extensionmanager/Classes/Exception/ExtensionManagerException.php
@@ -14,9 +14,11 @@ namespace TYPO3\CMS\Extensionmanager\Exception;
  * The TYPO3 project - inspiring people to share!
  */
 
+use TYPO3\CMS\Extensionmanager\Exception;
+
 /**
  * An exception when something is wrong within the extension manager
  */
-class ExtensionManagerException extends \TYPO3\CMS\Core\Exception
+class ExtensionManagerException extends Exception
 {
 }
diff --git a/typo3/sysext/form/Classes/Exception.php b/typo3/sysext/form/Classes/Exception.php
index bd686473e717..47e8f640a075 100644
--- a/typo3/sysext/form/Classes/Exception.php
+++ b/typo3/sysext/form/Classes/Exception.php
@@ -15,11 +15,13 @@ namespace TYPO3\CMS\Form;
  * The TYPO3 project - inspiring people to share!
  */
 
+use TYPO3\CMS\Core\Error\Exception as CoreException;
+
 /**
  * A generic Form Exception
  *
  * @api
  */
-class Exception extends \Exception
+class Exception extends CoreException
 {
 }
diff --git a/typo3/sysext/frontend/Classes/Exception.php b/typo3/sysext/frontend/Classes/Exception.php
index ae671e6fa8bf..1ce1350e82bf 100644
--- a/typo3/sysext/frontend/Classes/Exception.php
+++ b/typo3/sysext/frontend/Classes/Exception.php
@@ -14,9 +14,11 @@ namespace TYPO3\CMS\Frontend;
  * The TYPO3 project - inspiring people to share!
  */
 
+use TYPO3\CMS\Core\Exception as CoreException;
+
 /**
- * A generic frontend exception
+ * A generic Frontend exception
  */
-class Exception extends \Exception
+class Exception extends CoreException
 {
 }
diff --git a/typo3/sysext/install/Classes/Exception.php b/typo3/sysext/install/Classes/Exception.php
index 07d334d6d9d5..6cc93a2cf0e3 100644
--- a/typo3/sysext/install/Classes/Exception.php
+++ b/typo3/sysext/install/Classes/Exception.php
@@ -14,9 +14,11 @@ namespace TYPO3\CMS\Install;
  * The TYPO3 project - inspiring people to share!
  */
 
+use TYPO3\CMS\Core\Exception as CoreException;
+
 /**
- * A generic install exception
+ * A generic Install exception
  */
-class Exception extends \Exception
+class Exception extends CoreException
 {
 }
diff --git a/typo3/sysext/lang/Classes/Exception.php b/typo3/sysext/lang/Classes/Exception.php
new file mode 100644
index 000000000000..b26de6e5d905
--- /dev/null
+++ b/typo3/sysext/lang/Classes/Exception.php
@@ -0,0 +1,24 @@
+<?php
+namespace TYPO3\CMS\Lang;
+
+/*
+ * This file is part of the TYPO3 CMS project.
+ *
+ * It is free software; you can redistribute it and/or modify it under
+ * the terms of the GNU General Public License, either version 2
+ * of the License, or any later version.
+ *
+ * For the full copyright and license information, please read the
+ * LICENSE.txt file that was distributed with this source code.
+ *
+ * The TYPO3 project - inspiring people to share!
+ */
+
+use TYPO3\CMS\Core\Exception as CoreException;
+
+/**
+ * A generic Lang exception
+ */
+class Exception extends CoreException
+{
+}
diff --git a/typo3/sysext/lang/Classes/Exception/Language.php b/typo3/sysext/lang/Classes/Exception/Language.php
index 1479bb4a8f0c..62a0128c21f4 100644
--- a/typo3/sysext/lang/Classes/Exception/Language.php
+++ b/typo3/sysext/lang/Classes/Exception/Language.php
@@ -14,9 +14,11 @@ namespace TYPO3\CMS\Lang\Exception;
  * The TYPO3 project - inspiring people to share!
  */
 
+use TYPO3\CMS\Lang\Exception;
+
 /**
  * An exception when something is wrong within the language
  */
-class Language extends \TYPO3\CMS\Core\Exception
+class Language extends Exception
 {
 }
diff --git a/typo3/sysext/lang/Classes/Exception/Ter.php b/typo3/sysext/lang/Classes/Exception/Ter.php
index 21e7a5a09e7e..42993de7fd60 100644
--- a/typo3/sysext/lang/Classes/Exception/Ter.php
+++ b/typo3/sysext/lang/Classes/Exception/Ter.php
@@ -14,9 +14,11 @@ namespace TYPO3\CMS\Lang\Exception;
  * The TYPO3 project - inspiring people to share!
  */
 
+use TYPO3\CMS\Lang\Exception;
+
 /**
  * An exception when something is wrong within the ter
  */
-class Ter extends \TYPO3\CMS\Core\Exception
+class Ter extends Exception
 {
 }
diff --git a/typo3/sysext/lang/Classes/Exception/XmlParser.php b/typo3/sysext/lang/Classes/Exception/XmlParser.php
index 3f7f4a510d33..3564f5662760 100644
--- a/typo3/sysext/lang/Classes/Exception/XmlParser.php
+++ b/typo3/sysext/lang/Classes/Exception/XmlParser.php
@@ -14,9 +14,11 @@ namespace TYPO3\CMS\Lang\Exception;
  * The TYPO3 project - inspiring people to share!
  */
 
+use TYPO3\CMS\Lang\Exception;
+
 /**
  * An exception when something is wrong within parsing the xml
  */
-class XmlParser extends \TYPO3\CMS\Core\Exception
+class XmlParser extends Exception
 {
 }
-- 
GitLab