diff --git a/lib/Doctrine/ORM/EntityManager.php b/lib/Doctrine/ORM/EntityManager.php index d4b032bfc..839505345 100644 --- a/lib/Doctrine/ORM/EntityManager.php +++ b/lib/Doctrine/ORM/EntityManager.php @@ -19,7 +19,6 @@ namespace Doctrine\ORM; -use Exception; use Doctrine\Common\EventManager; use Doctrine\DBAL\Connection; use Doctrine\DBAL\DriverManager; @@ -28,6 +27,7 @@ use Doctrine\ORM\Query\ResultSetMapping; use Doctrine\ORM\Proxy\ProxyFactory; use Doctrine\ORM\Query\FilterCollection; use Doctrine\Common\Util\ClassUtils; +use Throwable; /** * The EntityManager is the central access point to ORM functionality. @@ -237,7 +237,7 @@ use Doctrine\Common\Util\ClassUtils; $this->conn->commit(); return $return ?: true; - } catch (Exception $e) { + } catch (Throwable $e) { $this->close(); $this->conn->rollBack(); diff --git a/lib/Doctrine/ORM/Query/Exec/MultiTableDeleteExecutor.php b/lib/Doctrine/ORM/Query/Exec/MultiTableDeleteExecutor.php index aaf94d7ff..2f3d5acf5 100644 --- a/lib/Doctrine/ORM/Query/Exec/MultiTableDeleteExecutor.php +++ b/lib/Doctrine/ORM/Query/Exec/MultiTableDeleteExecutor.php @@ -23,6 +23,7 @@ use Doctrine\DBAL\Connection; use Doctrine\DBAL\Types\Type; use Doctrine\ORM\Query\AST; use Doctrine\ORM\Utility\PersisterHelper; +use Throwable; /** * Executes the SQL statements for bulk DQL DELETE statements on classes in @@ -129,7 +130,7 @@ class MultiTableDeleteExecutor extends AbstractSqlExecutor foreach ($this->_sqlStatements as $sql) { $conn->executeUpdate($sql); } - } catch (\Exception $exception) { + } catch (Throwable $exception) { // FAILURE! Drop temporary table to avoid possible collisions $conn->executeUpdate($this->_dropTempTableSql); diff --git a/lib/Doctrine/ORM/Query/Exec/MultiTableUpdateExecutor.php b/lib/Doctrine/ORM/Query/Exec/MultiTableUpdateExecutor.php index acad25a92..7f13ed5f6 100644 --- a/lib/Doctrine/ORM/Query/Exec/MultiTableUpdateExecutor.php +++ b/lib/Doctrine/ORM/Query/Exec/MultiTableUpdateExecutor.php @@ -24,6 +24,7 @@ use Doctrine\DBAL\Types\Type; use Doctrine\ORM\Query\ParameterTypeInferer; use Doctrine\ORM\Query\AST; use Doctrine\ORM\Utility\PersisterHelper; +use Throwable; /** * Executes the SQL statements for bulk DQL UPDATE statements on classes in @@ -188,7 +189,7 @@ class MultiTableUpdateExecutor extends AbstractSqlExecutor $conn->executeUpdate($statement, $paramValues, $paramTypes); } - } catch (\Exception $exception) { + } catch (Throwable $exception) { // FAILURE! Drop temporary table to avoid possible collisions $conn->executeUpdate($this->_dropTempTableSql); diff --git a/lib/Doctrine/ORM/Tools/Console/Command/EnsureProductionSettingsCommand.php b/lib/Doctrine/ORM/Tools/Console/Command/EnsureProductionSettingsCommand.php index 499565a01..180254f9c 100644 --- a/lib/Doctrine/ORM/Tools/Console/Command/EnsureProductionSettingsCommand.php +++ b/lib/Doctrine/ORM/Tools/Console/Command/EnsureProductionSettingsCommand.php @@ -23,6 +23,7 @@ use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; +use Throwable; /** * Command to ensure that Doctrine is properly configured for a production environment. @@ -72,7 +73,7 @@ EOT if ($input->getOption('complete') !== null) { $em->getConnection()->connect(); } - } catch (\Exception $e) { + } catch (Throwable $e) { $output->writeln('' . $e->getMessage() . ''); return 1; diff --git a/lib/Doctrine/ORM/Tools/SchemaTool.php b/lib/Doctrine/ORM/Tools/SchemaTool.php index 007ac85a8..6609b5ea0 100644 --- a/lib/Doctrine/ORM/Tools/SchemaTool.php +++ b/lib/Doctrine/ORM/Tools/SchemaTool.php @@ -92,7 +92,7 @@ class SchemaTool foreach ($createSchemaSql as $sql) { try { $conn->executeQuery($sql); - } catch (\Exception $e) { + } catch (\Throwable $e) { throw ToolsException::schemaToolFailure($sql, $e); } } @@ -742,8 +742,8 @@ class SchemaTool foreach ($dropSchemaSql as $sql) { try { $conn->executeQuery($sql); - } catch (\Exception $e) { - + } catch (\Throwable $e) { + // ignored } } } diff --git a/lib/Doctrine/ORM/Tools/ToolsException.php b/lib/Doctrine/ORM/Tools/ToolsException.php index 0a4616404..95b3af0ac 100644 --- a/lib/Doctrine/ORM/Tools/ToolsException.php +++ b/lib/Doctrine/ORM/Tools/ToolsException.php @@ -20,6 +20,7 @@ namespace Doctrine\ORM\Tools; use Doctrine\ORM\ORMException; +use Throwable; /** * Tools related Exceptions. @@ -28,13 +29,7 @@ use Doctrine\ORM\ORMException; */ class ToolsException extends ORMException { - /** - * @param string $sql - * @param \Exception $e - * - * @return ToolsException - */ - public static function schemaToolFailure($sql, \Exception $e) + public static function schemaToolFailure(string $sql, Throwable $e) : self { return new self("Schema-Tool failed with Error '" . $e->getMessage() . "' while executing DDL: " . $sql, "0", $e); } diff --git a/lib/Doctrine/ORM/UnitOfWork.php b/lib/Doctrine/ORM/UnitOfWork.php index 0edd756f0..05ad599a4 100644 --- a/lib/Doctrine/ORM/UnitOfWork.php +++ b/lib/Doctrine/ORM/UnitOfWork.php @@ -43,8 +43,8 @@ use Doctrine\ORM\Persisters\Entity\JoinedSubclassPersister; use Doctrine\ORM\Persisters\Entity\SingleTablePersister; use Doctrine\ORM\Proxy\Proxy; use Doctrine\ORM\Utility\IdentifierFlattener; -use Exception; use InvalidArgumentException; +use Throwable; use UnexpectedValueException; /** @@ -411,7 +411,7 @@ class UnitOfWork implements PropertyChangedListener } $conn->commit(); - } catch (Exception $e) { + } catch (Throwable $e) { $this->em->close(); $conn->rollBack(); diff --git a/tests/Doctrine/Tests/ORM/EntityManagerTest.php b/tests/Doctrine/Tests/ORM/EntityManagerTest.php index 7f36bb285..0191ba158 100644 --- a/tests/Doctrine/Tests/ORM/EntityManagerTest.php +++ b/tests/Doctrine/Tests/ORM/EntityManagerTest.php @@ -232,6 +232,24 @@ class EntityManagerTest extends OrmTestCase EntityManager::create(1, $config); } + /** + * @group #5796 + */ + public function testTransactionalReThrowsThrowables() + { + try { + $this->_em->transactional(function () { + (function (array $value) { + // this only serves as an IIFE that throws a `TypeError` + })(null); + }); + + self::fail('TypeError expected to be thrown'); + } catch (\TypeError $ignored) { + self::assertFalse($this->_em->isOpen()); + } + } + /** * @group 6017 */