Issue #1992950 by xjm: Stop use-ing Exception.

8.0.x
Nathaniel Catchpole 2013-05-16 09:15:22 +01:00
parent b18ad40678
commit 261b71d29c
35 changed files with 56 additions and 119 deletions

View File

@ -42,8 +42,6 @@
namespace Drupal\Component\Archiver;
use Exception;
//require_once 'PEAR.php';
//
//
@ -636,7 +634,7 @@ class ArchiveTar // extends PEAR
{
// ----- To be completed
// $this->raiseError($p_message);
throw new Exception($p_message);
throw new \Exception($p_message);
}
// }}}
@ -645,7 +643,7 @@ class ArchiveTar // extends PEAR
{
// ----- To be completed
// $this->raiseError($p_message);
throw new Exception($p_message);
throw new \Exception($p_message);
}
// }}}

View File

@ -7,10 +7,8 @@
namespace Drupal\Component\Archiver;
use Exception;
/**
* Defines an exception class for Drupal\Component\Archiver\ArchiverInterface.
*/
class ArchiverException extends Exception {
}
class ArchiverException extends \Exception {}

View File

@ -7,9 +7,7 @@
namespace Drupal\Component\Plugin\Exception;
use Exception;
/**
* An exception class to be thrown for context plugin exceptions.
*/
class ContextException extends Exception implements ExceptionInterface { }
class ContextException extends \Exception implements ExceptionInterface { }

View File

@ -6,10 +6,8 @@
namespace Drupal\Component\Plugin\Exception;
use Exception;
/**
* Generic Plugin exception class to be thrown when no more specific class
* is applicable.
*/
class PluginException extends Exception implements ExceptionInterface { }
class PluginException extends \Exception implements ExceptionInterface { }

View File

@ -9,7 +9,6 @@ namespace Drupal\Core\Config;
use Drupal\Core\Database\Database;
use Drupal\Core\Database\Connection;
use Exception;
/**
* Defines the Database storage controller.
@ -81,7 +80,7 @@ class DatabaseStorage implements StorageInterface {
$data = $this->decode($raw);
}
}
catch (Exception $e) {
catch (\Exception $e) {
}
return $data;
}

View File

@ -13,8 +13,6 @@ use Drupal\Core\Database\SchemaObjectExistsException;
use Drupal\Core\Database\SchemaObjectDoesNotExistException;
use Drupal\Core\Database\Schema as DatabaseSchema;
use Exception;
/**
* @addtogroup schemaapi
* @{
@ -516,7 +514,7 @@ class Schema extends DatabaseSchema {
$this->connection->queryRange("SELECT 1 FROM {" . $table . "}", 0, 1);
return TRUE;
}
catch (Exception $e) {
catch (\Exception $e) {
return FALSE;
}
}
@ -533,7 +531,7 @@ class Schema extends DatabaseSchema {
$this->connection->queryRange("SELECT $column FROM {" . $table . "}", 0, 1);
return TRUE;
}
catch (Exception $e) {
catch (\Exception $e) {
return FALSE;
}
}

View File

@ -12,8 +12,6 @@ use Drupal\Core\Database\Install\Tasks as InstallTasks;
use Drupal\Core\Database\Driver\pgsql\Connection;
use Drupal\Core\Database\DatabaseNotFoundException;
use Exception;
/**
* PostgreSQL specific install functions
*/
@ -55,7 +53,7 @@ class Tasks extends InstallTasks {
Database::getConnection();
$this->pass('Drupal can CONNECT to the database ok.');
}
catch (Exception $e) {
catch (\Exception $e) {
// Attempt to create the database if it is not found.
if ($e->getCode() == Connection::DATABASE_NOT_FOUND) {
// Remove the database string from connection info.
@ -118,7 +116,7 @@ class Tasks extends InstallTasks {
$this->fail(st($text, $replacements));
}
}
catch (Exception $e) {
catch (\Exception $e) {
$this->fail(st('Drupal could not determine the encoding of the database was set to UTF-8'));
}
}
@ -145,7 +143,7 @@ class Tasks extends InstallTasks {
try {
db_query($query);
}
catch (Exception $e) {
catch (\Exception $e) {
// Ignore possible errors when the user doesn't have the necessary
// privileges to ALTER the database.
}
@ -233,7 +231,7 @@ class Tasks extends InstallTasks {
$this->pass(st('PostgreSQL has initialized itself.'));
}
catch (Exception $e) {
catch (\Exception $e) {
$this->fail(st('Drupal could not be correctly setup with the existing database. Revise any errors.'));
}
}

View File

@ -13,8 +13,6 @@ use Drupal\Core\Database\SchemaObjectExistsException;
use Drupal\Core\Database\SchemaObjectDoesNotExistException;
use Drupal\Core\Database\Schema as DatabaseSchema;
use Exception;
/**
* @addtogroup schemaapi
* @{

View File

@ -16,7 +16,6 @@ use Drupal\Core\Database\Driver\sqlite\Statement;
use Drupal\Core\Database\Connection as DatabaseConnection;
use PDO;
use Exception;
use SplFileInfo;
/**
@ -161,7 +160,7 @@ class Connection extends DatabaseConnection {
unlink($this->connectionOptions['database'] . '-' . $prefix);
}
}
catch (Exception $e) {
catch (\Exception $e) {
// Ignore the exception and continue. There is nothing we can do here
// to report the error or fail safe.
}

View File

@ -12,8 +12,6 @@ use Drupal\Core\Database\Driver\sqlite\Connection;
use Drupal\Core\Database\DatabaseNotFoundException;
use Drupal\Core\Database\Install\Tasks as InstallTasks;
use Exception;
class Tasks extends InstallTasks {
protected $pdoDriver = 'sqlite';
@ -56,7 +54,7 @@ class Tasks extends InstallTasks {
Database::getConnection();
$this->pass('Drupal can CONNECT to the database ok.');
}
catch (Exception $e) {
catch (\Exception $e) {
// Attempt to create the database if it is not found.
if ($e->getCode() == Connection::DATABASE_NOT_FOUND) {
// Remove the database string from connection info.

View File

@ -11,9 +11,6 @@ use Drupal\Core\Database\SchemaObjectExistsException;
use Drupal\Core\Database\SchemaObjectDoesNotExistException;
use Drupal\Core\Database\Schema as DatabaseSchema;
use Exception;
/**
* @ingroup schemaapi
* @{
@ -451,7 +448,7 @@ class Schema extends DatabaseSchema {
}
}
else {
new Exception("Unable to parse the column type " . $row->type);
new \Exception("Unable to parse the column type " . $row->type);
}
}
$indexes = array();

View File

@ -10,7 +10,6 @@ namespace Drupal\Core\Database\Install;
use Drupal\Core\Database\Database;
use PDO;
use Exception;
/**
* Database installer structure.
@ -166,7 +165,7 @@ abstract class Tasks {
Database::getConnection();
$this->pass('Drupal can CONNECT to the database ok.');
}
catch (Exception $e) {
catch (\Exception $e) {
$this->fail(st('Failed to connect to your database server. The server reports the following message: %error.<ul><li>Is the database server running?</li><li>Does the database exist, and have you entered the correct database name?</li><li>Have you entered the correct username and password?</li><li>Have you entered the correct database hostname?</li></ul>', array('%error' => $e->getMessage())));
return FALSE;
}
@ -181,7 +180,7 @@ abstract class Tasks {
db_query($query);
$this->pass(st($pass));
}
catch (Exception $e) {
catch (\Exception $e) {
$this->fail(st($fail, array('%query' => $query, '%error' => $e->getMessage(), '%name' => $this->name())));
return !$fatal;
}

View File

@ -9,8 +9,6 @@ namespace Drupal\Core\Database\Query;
use Drupal\Core\Database\Database;
use Exception;
/**
* General class for an abstracted INSERT query.
*/
@ -220,7 +218,7 @@ class Insert extends Query {
$last_insert_id = $this->connection->query($sql, $insert_values, $this->queryOptions);
}
}
catch (Exception $e) {
catch (\Exception $e) {
// One of the INSERTs failed, rollback the whole batch.
$transaction->rollback();
// Rethrow the exception for the calling code.

View File

@ -7,9 +7,7 @@
namespace Drupal\Core\Entity;
use Exception;
/**
* Defines an exception thrown when a malformed entity is passed.
*/
class EntityMalformedException extends Exception { }
class EntityMalformedException extends \Exception { }

View File

@ -7,9 +7,7 @@
namespace Drupal\Core\Entity;
use Exception;
/**
* Defines an exception thrown when storage operations fail.
*/
class EntityStorageException extends Exception { }
class EntityStorageException extends \Exception { }

View File

@ -6,11 +6,9 @@
namespace Drupal\Core\Executable;
use Exception;
use Drupal\Component\Plugin\Exception\ExceptionInterface;
/**
* Generic executable plugin exception class.
*/
class ExecutableException extends Exception implements ExceptionInterface {
}
class ExecutableException extends \Exception implements ExceptionInterface {}

View File

@ -7,11 +7,7 @@
namespace Drupal\Core\TypedData;
use Exception;
/**
* Exception thrown when data wrappers miss contextual information.
*/
class MissingContextException extends Exception {
}
class MissingContextException extends \Exception {}

View File

@ -7,11 +7,7 @@
namespace Drupal\Core\TypedData;
use Exception;
/**
* Exception thrown when trying to write or set ready-only data.
*/
class ReadOnlyException extends Exception {
}
class ReadOnlyException extends \Exception {}

View File

@ -7,8 +7,6 @@
namespace Drupal\Core\Updater;
use Exception;
/**
* Defines a Exception class for the Drupal\Core\Updater\Updater class
* hierarchy.
@ -17,5 +15,4 @@ use Exception;
* specific name so that call sites that want to tell the difference can
* specifically catch these exceptions and treat them differently.
*/
class UpdaterException extends Exception {
}
class UpdaterException extends \Exception {}

View File

@ -7,9 +7,7 @@
namespace Drupal\Core\Utility;
use Exception;
/**
* Exception class used to throw error if a module update fails.
*/
class UpdateException extends Exception { }
class UpdateException extends \Exception { }

View File

@ -8,7 +8,6 @@
namespace Drupal\field\Tests;
use Drupal\field\FieldException;
use Exception;
class CrudTest extends FieldUnitTestBase {
@ -168,7 +167,7 @@ class CrudTest extends FieldUnitTestBase {
$field = field_create_field($field_definition);
$this->assertTrue(FALSE, 'Field creation (correctly) fails.');
}
catch (Exception $e) {
catch (\Exception $e) {
$this->assertTrue(TRUE, 'Field creation (correctly) fails.');
}

View File

@ -10,7 +10,6 @@ namespace Drupal\field_sql_storage\Tests;
use Drupal\Core\Database\Database;
use Drupal\field\FieldException;
use Drupal\system\Tests\Entity\EntityUnitTestBase;
use Exception;
use PDO;
/**
@ -339,7 +338,7 @@ class FieldSqlStorageTest extends EntityUnitTestBase {
field_update_field($field);
$this->fail(t('Update succeeded.'));
}
catch (Exception $e) {
catch (\Exception $e) {
$this->pass(t('Update properly failed.'));
}

View File

@ -10,7 +10,6 @@ namespace Drupal\locale;
use Drupal\Component\Gettext\PoStreamReader;
use Drupal\Component\Gettext\PoMemoryWriter;
use Drupal\locale\PoDatabaseWriter;
use Exception;
/**
* Static class providing Drupal specific Gettext functionality.
@ -89,13 +88,13 @@ class Gettext {
try {
$reader->open();
}
catch (Exception $exception) {
catch (\Exception $exception) {
throw $exception;
}
$header = $reader->getHeader();
if (!$header) {
throw new Exception('Missing or malformed header.');
throw new \Exception('Missing or malformed header.');
}
// Initialize the database writer.
@ -115,7 +114,7 @@ class Gettext {
}
$writer->writeItems($reader, $options['items']);
}
catch (Exception $exception) {
catch (\Exception $exception) {
throw $exception;
}

View File

@ -7,9 +7,7 @@
namespace Drupal\locale;
use Exception;
/**
* Defines an exception thrown when storage operations fail.
*/
class StringStorageException extends Exception { }
class StringStorageException extends \Exception { }

View File

@ -8,7 +8,6 @@
namespace Drupal\node\Tests;
use Drupal\Core\Database\Database;
use Exception;
/**
* Tests creating and saving a node.
@ -75,7 +74,7 @@ class NodeCreationTest extends NodeTestBase {
entity_create('node', $edit)->save();
$this->fail(t('Expected exception has not been thrown.'));
}
catch (Exception $e) {
catch (\Exception $e) {
$this->pass(t('Expected exception has been thrown.'));
}

View File

@ -7,8 +7,6 @@
namespace Drupal\node\Tests;
use Exception;
/**
* Tests node_query_node_access_alter().
*/
@ -100,7 +98,7 @@ class NodeQueryAlterTest extends NodeTestBase {
$result = $query->execute()->fetchAll();
$this->assertEqual(count($result), 4, 'User with access can see correct nodes');
}
catch (Exception $e) {
catch (\Exception $e) {
$this->fail(t('Altered query is malformed'));
}
}
@ -123,7 +121,7 @@ class NodeQueryAlterTest extends NodeTestBase {
$result = $query->execute()->fetchAll();
$this->assertEqual(count($result), 0, 'User with no access cannot see nodes');
}
catch (Exception $e) {
catch (\Exception $e) {
$this->fail(t('Altered query is malformed'));
}
}
@ -146,7 +144,7 @@ class NodeQueryAlterTest extends NodeTestBase {
$result = $query->execute()->fetchAll();
$this->assertEqual(count($result), 0, 'User with view-only access cannot edit nodes');
}
catch (Exception $e) {
catch (\Exception $e) {
$this->fail($e->getMessage());
$this->fail((string) $query);
$this->fail(t('Altered query is malformed'));
@ -186,7 +184,7 @@ class NodeQueryAlterTest extends NodeTestBase {
$result = $query->execute()->fetchAll();
$this->assertEqual(count($result), 0, 'User view privileges are not overridden');
}
catch (Exception $e) {
catch (\Exception $e) {
$this->fail(t('Altered query is malformed'));
}
@ -208,7 +206,7 @@ class NodeQueryAlterTest extends NodeTestBase {
$result = $query->execute()->fetchAll();
$this->assertEqual(count($result), 4, 'User view privileges are overridden');
}
catch (Exception $e) {
catch (\Exception $e) {
$this->fail(t('Altered query is malformed'));
}
state()->delete('node_access_test.no_access_uid');

View File

@ -14,7 +14,6 @@ use Drupal\Core\Database\ConnectionNotDefinedException;
use Drupal\Core\DrupalKernel;
use ReflectionMethod;
use ReflectionObject;
use Exception;
/**
* Base class for Drupal tests.
@ -733,7 +732,7 @@ abstract class TestBase {
$this->$method();
// Finish up.
}
catch (Exception $e) {
catch (\Exception $e) {
$this->exceptionHandler($e);
}
$this->tearDown();

View File

@ -8,7 +8,6 @@
namespace Drupal\system\Tests\Database;
use Drupal\Core\Database\IntegrityConstraintViolationException;
use Exception;
/**
* Tests invalid data handling.

View File

@ -10,8 +10,6 @@ namespace Drupal\system\Tests\Database;
use Drupal\Core\Database\Database;
use Drupal\simpletest\UnitTestBase;
use Exception;
/**
* Tests the Schema API.
*/
@ -141,7 +139,7 @@ class SchemaTest extends UnitTestBase {
try {
db_create_table('test_timestamp', $table_specification);
}
catch (Exception $e) {}
catch (\Exception $e) {}
$this->assertTrue(db_table_exists('test_timestamp'), 'Table with database specific datatype was created.');
}
@ -161,7 +159,7 @@ class SchemaTest extends UnitTestBase {
->execute();
return TRUE;
}
catch (Exception $e) {
catch (\Exception $e) {
return FALSE;
}
}
@ -233,7 +231,7 @@ class SchemaTest extends UnitTestBase {
->execute();
return TRUE;
}
catch (Exception $e) {
catch (\Exception $e) {
return FALSE;
}
}

View File

@ -10,7 +10,6 @@ namespace Drupal\system\Tests\Database;
use Drupal\Core\Database\Database;
use Drupal\Core\Database\TransactionOutOfOrderException;
use Drupal\Core\Database\TransactionNoActiveException;
use Exception;
/**
* Tests transaction support, particularly nesting.
@ -176,7 +175,7 @@ class TransactionTest extends DatabaseTestBase {
$saved_age = db_query('SELECT age FROM {test} WHERE name = :name', array(':name' => 'DanielB'))->fetchField();
$this->assertNotIdentical($saved_age, '19', 'Cannot retrieve DanielB row after commit.');
}
catch (Exception $e) {
catch (\Exception $e) {
$this->fail($e->getMessage());
}
}
@ -202,7 +201,7 @@ class TransactionTest extends DatabaseTestBase {
$saved_age = db_query('SELECT age FROM {test} WHERE name = :name', array(':name' => 'DanielB'))->fetchField();
$this->assertIdentical($saved_age, '19', 'DanielB not rolled back, since transactions are not supported.');
}
catch (Exception $e) {
catch (\Exception $e) {
$this->fail($e->getMessage());
}
}
@ -224,7 +223,7 @@ class TransactionTest extends DatabaseTestBase {
$saved_age = db_query('SELECT age FROM {test} WHERE name = :name', array(':name' => 'DanielA'))->fetchField();
$this->assertIdentical($saved_age, '19', 'Can retrieve DanielA row after commit.');
}
catch (Exception $e) {
catch (\Exception $e) {
$this->fail($e->getMessage());
}
}

View File

@ -7,8 +7,6 @@
namespace Drupal\system\Tests\Entity;
use Exception;
use InvalidArgumentException;
use Drupal\simpletest\WebTestBase;
use Drupal\Core\Language\Language;

View File

@ -8,7 +8,6 @@
namespace Drupal\system\Tests\Plugin;
use Drupal\Component\Plugin\Exception\ExceptionInterface;
use Exception;
use Drupal\plugin_test\Plugin\AlterDecoratorTestPluginManager;
use Drupal\plugin_test\Plugin\TestPluginManager;
use Drupal\simpletest\WebTestBase;

View File

@ -8,7 +8,6 @@
namespace Drupal\system\Tests\Plugin;
use Drupal\Component\Plugin\Exception\ExceptionInterface;
use Exception;
/**
* Tests that plugins are correctly instantiated.
@ -41,7 +40,7 @@ class FactoryTest extends PluginTestBase {
catch (ExceptionInterface $e) {
$this->pass('Drupal\Component\Plugin\Exception\ExceptionInterface expected and caught.');
}
catch (Exception $e) {
catch (\Exception $e) {
$this->fail('Drupal\Component\Plugin\Exception\ExceptionInterface expected, but ' . get_class($e) . ' was thrown.');
}
}
@ -78,7 +77,7 @@ class FactoryTest extends PluginTestBase {
catch (ExceptionInterface $e) {
$this->pass('Drupal\Component\Plugin\Exception\ExceptionInterface expected and caught.');
}
catch (Exception $e) {
catch (\Exception $e) {
$this->fail('An unexpected Exception of type "' . get_class($e) . '" was thrown with message ' . $e->getMessage());
}
}

View File

@ -18,8 +18,6 @@ use Drupal\Core\Routing\RouteProvider;
use Drupal\Core\Database\Database;
use Drupal\Core\Routing\MatcherDumper;
use Exception;
/**
* Basic tests for the RouteProvider.
*/
@ -329,7 +327,7 @@ class RouteProviderTest extends UnitTestBase {
$routes = $provider->getRouteCollectionForRequest($request);
$this->fail(t('No exception was thrown.'));
}
catch (Exception $e) {
catch (\Exception $e) {
$this->assertTrue($e instanceof ResourceNotFoundException, 'The correct exception was thrown.');
}
}

View File

@ -10,7 +10,6 @@ namespace Drupal\system\Tests\Upgrade;
use Drupal\Component\Utility\Crypt;
use Drupal\Core\Database\Database;
use Drupal\simpletest\WebTestBase;
use Exception;
use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
use Symfony\Component\HttpFoundation\Request;
@ -188,7 +187,7 @@ abstract class UpgradePathTestBase extends WebTestBase {
}
// Since cache_bootstrap won't exist in a Drupal 6 site, ignore the
// exception if the above fails.
catch (Exception $e) {}
catch (\Exception $e) {}
}
/**
@ -220,12 +219,12 @@ abstract class UpgradePathTestBase extends WebTestBase {
// Load the first update screen.
$this->getUpdatePhp();
if (!$this->assertResponse(200)) {
throw new Exception('Initial GET to update.php did not return HTTP 200 status.');
throw new \Exception('Initial GET to update.php did not return HTTP 200 status.');
}
// Ensure that the first update screen appeared correctly.
if (!$this->assertFieldByXPath('//input[@type="submit"]')) {
throw new Exception('An error was encountered during the first access to update.php.');
throw new \Exception('An error was encountered during the first access to update.php.');
}
// Initialize config directories and rebuild the service container after
@ -236,7 +235,7 @@ abstract class UpgradePathTestBase extends WebTestBase {
// Continue.
$this->drupalPost(NULL, array(), t('Continue'));
if (!$this->assertResponse(200)) {
throw new Exception('POST to continue update.php did not return HTTP 200 status.');
throw new \Exception('POST to continue update.php did not return HTTP 200 status.');
}
// The test should pass if there are no pending updates.
@ -250,12 +249,12 @@ abstract class UpgradePathTestBase extends WebTestBase {
// Go!
$this->drupalPost(NULL, array(), t('Apply pending updates'));
if (!$this->assertResponse(200)) {
throw new Exception('POST to update.php to apply pending updates did not return HTTP 200 status.');
throw new \Exception('POST to update.php to apply pending updates did not return HTTP 200 status.');
}
if (!$this->assertNoText(t('An unrecoverable error has occurred.'))) {
// Error occured during update process.
throw new Exception('POST to update.php to apply pending updates detected an unrecoverable error.');
throw new \Exception('POST to update.php to apply pending updates detected an unrecoverable error.');
}
// Check for errors during the update process.
@ -269,7 +268,7 @@ abstract class UpgradePathTestBase extends WebTestBase {
if (!empty($this->upgradeErrors)) {
// Upgrade failed, the installation might be in an inconsistent state,
// don't process.
throw new Exception('Errors during update process.');
throw new \Exception('Errors during update process.');
}
// Allow tests to check the completion page.
@ -279,7 +278,7 @@ abstract class UpgradePathTestBase extends WebTestBase {
$this->getUpdatePhp();
$this->drupalPost(NULL, array(), t('Continue'));
if (!$this->assertText(t('No pending updates.'), 'No pending updates at the end of the update process.')) {
throw new Exception('update.php still shows pending updates after execution.');
throw new \Exception('update.php still shows pending updates after execution.');
}
// Upgrade succeed, rebuild the environment so that we can call the API