From 58638216e89d8b33e0c0e9879564135ba53ca15f Mon Sep 17 00:00:00 2001 From: Phill Sparks Date: Tue, 15 Nov 2011 12:35:04 +0000 Subject: [PATCH] Throw better Exceptions --- laravel/asset.php | 6 +++--- laravel/cache/manager.php | 2 +- laravel/cookie.php | 4 ++-- laravel/crypter.php | 6 +++--- laravel/database/connectors/sqlite.php | 4 ++-- laravel/database/eloquent/hydrator.php | 4 ++-- laravel/database/manager.php | 6 +++--- laravel/database/query.php | 4 ++-- laravel/html.php | 4 ++-- laravel/input.php | 2 +- laravel/ioc.php | 4 ++-- laravel/lang.php | 4 ++-- laravel/memcached.php | 4 ++-- laravel/redirect.php | 4 ++-- laravel/redis.php | 10 +++++----- laravel/routing/controller.php | 4 ++-- laravel/routing/route.php | 6 +++--- laravel/session/drivers/factory.php | 4 ++-- laravel/session/payload.php | 4 ++-- laravel/str.php | 4 ++-- laravel/url.php | 6 +++--- laravel/validator.php | 4 ++-- laravel/view.php | 6 +++--- 23 files changed, 53 insertions(+), 53 deletions(-) diff --git a/laravel/asset.php b/laravel/asset.php index e06648f2..5b90a66a 100644 --- a/laravel/asset.php +++ b/laravel/asset.php @@ -303,12 +303,12 @@ protected function dependency_is_valid($asset, $dependency, $original, $assets) if ($dependency === $asset) { - throw new \Exception("Asset [$asset] is dependent on itself."); + throw new \LogicException("Asset [$asset] is dependent on itself."); } elseif (isset($assets[$dependency]) and in_array($asset, $assets[$dependency]['dependencies'])) { - throw new \Exception("Assets [$asset] and [$dependency] have a circular dependency."); + throw new \LogicException("Assets [$asset] and [$dependency] have a circular dependency."); } } -} \ No newline at end of file +} diff --git a/laravel/cache/manager.php b/laravel/cache/manager.php index d8eeaf5e..a216a2ea 100644 --- a/laravel/cache/manager.php +++ b/laravel/cache/manager.php @@ -65,7 +65,7 @@ protected static function factory($driver) return new Drivers\Redis(Redis::db()); default: - throw new \Exception("Cache driver {$driver} is not supported."); + throw new \DomainException("Cache driver {$driver} is not supported."); } } diff --git a/laravel/cookie.php b/laravel/cookie.php index 09094ddf..783ee161 100644 --- a/laravel/cookie.php +++ b/laravel/cookie.php @@ -2,7 +2,7 @@ if (trim(Config::$items['application']['key']) === '') { - throw new \Exception('The cookie class may not be used without an application key.'); + throw new \LogicException('The cookie class may not be used without an application key.'); } class Cookie { @@ -128,4 +128,4 @@ public static function forget($name) return static::put($name, null, -2000); } -} \ No newline at end of file +} diff --git a/laravel/crypter.php b/laravel/crypter.php index 51ff19bf..bb5435aa 100644 --- a/laravel/crypter.php +++ b/laravel/crypter.php @@ -2,7 +2,7 @@ if (trim(Config::$items['application']['key']) === '') { - throw new \Exception('The encryption class may not be used without an application key.'); + throw new \LogicException('The encryption class may not be used without an application key.'); } class Crypter { @@ -62,7 +62,7 @@ public static function decrypt($value) { if (($value = base64_decode($value)) === false) { - throw new \Exception('Decryption error. Input value is not valid base64 data.'); + throw new \InvalidArgumentException('Decryption error. Input value is not valid base64 data.'); } $iv = substr($value, 0, static::iv_size()); @@ -92,4 +92,4 @@ protected static function key() return Config::$items['application']['key']; } -} \ No newline at end of file +} diff --git a/laravel/database/connectors/sqlite.php b/laravel/database/connectors/sqlite.php index 1b5c367d..0ffe8ed6 100644 --- a/laravel/database/connectors/sqlite.php +++ b/laravel/database/connectors/sqlite.php @@ -52,7 +52,7 @@ public function connect($config) return new PDO('sqlite:'.$config['database'], null, null, $options); } - throw new \Exception("SQLite database [{$config['database']}] could not be found."); + throw new \OutOfBoundsException("SQLite database [{$config['database']}] could not be found."); } -} \ No newline at end of file +} diff --git a/laravel/database/eloquent/hydrator.php b/laravel/database/eloquent/hydrator.php index 49684bc9..7c188d63 100644 --- a/laravel/database/eloquent/hydrator.php +++ b/laravel/database/eloquent/hydrator.php @@ -18,7 +18,7 @@ public static function hydrate($eloquent) { if ( ! method_exists($eloquent, $include)) { - throw new \Exception("Attempting to eager load [$include], but the relationship is not defined."); + throw new \LogicException("Attempting to eager load [$include], but the relationship is not defined."); } static::eagerly($eloquent, $results, $include); @@ -209,4 +209,4 @@ private static function has_and_belongs_to_many($relationship, &$parents, $relat } } -} \ No newline at end of file +} diff --git a/laravel/database/manager.php b/laravel/database/manager.php index fa63c0e5..fa92e0ca 100644 --- a/laravel/database/manager.php +++ b/laravel/database/manager.php @@ -38,7 +38,7 @@ public static function connection($connection = null) if (is_null($config)) { - throw new \Exception("Database connection is not defined for connection [$connection]."); + throw new \OutOfBoundsException("Database connection is not defined for connection [$connection]."); } static::$connections[$connection] = new Connection(static::connect($config), $config); @@ -88,7 +88,7 @@ protected static function connector($driver) return new Connectors\Postgres; default: - throw new \Exception("Database driver [$driver] is not supported."); + throw new \DomainException("Database driver [$driver] is not supported."); } } @@ -127,4 +127,4 @@ public static function __callStatic($method, $parameters) return call_user_func_array(array(static::connection(), $method), $parameters); } -} \ No newline at end of file +} diff --git a/laravel/database/query.php b/laravel/database/query.php index c05ca07e..7adac35e 100644 --- a/laravel/database/query.php +++ b/laravel/database/query.php @@ -669,7 +669,7 @@ public function __call($method, $parameters) } } - throw new \Exception("Method [$method] is not defined on the Query class."); + throw new \BadMethodCallException("Method [$method] is not defined on the Query class."); } -} \ No newline at end of file +} diff --git a/laravel/html.php b/laravel/html.php index 736a760a..dd850b5b 100644 --- a/laravel/html.php +++ b/laravel/html.php @@ -376,7 +376,7 @@ public static function __callStatic($method, $parameters) return forward_static_call_array('HTML::link_to_route', $parameters); } - throw new \Exception("Method [$method] is not defined on the HTML class."); + throw new \BadMethodCallException("Method [$method] is not defined on the HTML class."); } -} \ No newline at end of file +} diff --git a/laravel/input.php b/laravel/input.php index b1ba37fd..a7825b35 100644 --- a/laravel/input.php +++ b/laravel/input.php @@ -123,7 +123,7 @@ public static function old($key = null, $default = null) { if (Config::get('session.driver') == '') { - throw new \Exception('A session driver must be specified in order to access old input.'); + throw new \UnexpectedValueException('A session driver must be specified in order to access old input.'); } $old = IoC::core('session')->get(Input::old_input, array()); diff --git a/laravel/ioc.php b/laravel/ioc.php index d4c33d59..349f698b 100644 --- a/laravel/ioc.php +++ b/laravel/ioc.php @@ -145,7 +145,7 @@ public static function resolve($name, $parameters = array()) if ( ! static::registered($name)) { - throw new \Exception("Error resolving [$name]. No resolver has been registered in the container."); + throw new \OutOfBoundsException("Error resolving [$name]. No resolver has been registered in the container."); } $object = call_user_func(static::$registry[$name]['resolver'], $parameters); @@ -165,4 +165,4 @@ public static function resolve($name, $parameters = array()) * loaded since there isn't any reason to load the container * configuration until the class is first requested. */ -IoC::bootstrap(); \ No newline at end of file +IoC::bootstrap(); diff --git a/laravel/lang.php b/laravel/lang.php index 0f24303f..c2b035f1 100644 --- a/laravel/lang.php +++ b/laravel/lang.php @@ -149,7 +149,7 @@ protected function parse($key) return array($segments[0], implode('.', array_slice($segments, 1))); } - throw new \Exception("Invalid language line [$key]. A specific line must be specified."); + throw new \InvalidArgumentException("Invalid language line [$key]. A specific line must be specified."); } /** @@ -188,4 +188,4 @@ public function __toString() return $this->get(); } -} \ No newline at end of file +} diff --git a/laravel/memcached.php b/laravel/memcached.php index 8089b21a..8565ea23 100644 --- a/laravel/memcached.php +++ b/laravel/memcached.php @@ -53,10 +53,10 @@ public static function connect($servers) if ($memcache->getVersion() === false) { - throw new \Exception('Could not establish memcached connection. Please verify your configuration.'); + throw new \RuntimeException('Could not establish memcached connection. Please verify your configuration.'); } return $memcache; } -} \ No newline at end of file +} diff --git a/laravel/redirect.php b/laravel/redirect.php index a891b387..2d13aa1e 100644 --- a/laravel/redirect.php +++ b/laravel/redirect.php @@ -56,7 +56,7 @@ public function with($key, $value) { if (Config::get('session.driver') == '') { - throw new \Exception('A session driver must be set before setting flash data.'); + throw new \LogicException('A session driver must be set before setting flash data.'); } IoC::core('session')->flash($key, $value); @@ -91,7 +91,7 @@ public static function __callStatic($method, $parameters) return static::to(URL::to_route(substr($method, 3), $parameters), $status); } - throw new \Exception("Method [$method] is not defined on the Redirect class."); + throw new \BadMethodCallException("Method [$method] is not defined on the Redirect class."); } } diff --git a/laravel/redis.php b/laravel/redis.php index c71047e6..85da0511 100644 --- a/laravel/redis.php +++ b/laravel/redis.php @@ -65,7 +65,7 @@ public static function db($name = 'default') { if (is_null($config = Config::get("database.redis.{$name}"))) { - throw new \Exception("Redis database [$name] is not defined."); + throw new \DomainException("Redis database [$name] is not defined."); } static::$databases[$name] = new static($config['host'], $config['port']); @@ -98,7 +98,7 @@ public function run($method, $parameters) switch (substr($ersponse, 0, 1)) { case '-': - throw new \Exception('Redis error: '.substr(trim($ersponse), 4)); + throw new \RuntimeException('Redis error: '.substr(trim($ersponse), 4)); case '+': case ':': @@ -111,7 +111,7 @@ public function run($method, $parameters) return $this->multibulk($ersponse); default: - throw new \Exception("Unknown response from Redis server: ".substr($ersponse, 0, 1)); + throw new \UnexpectedValueException("Unknown response from Redis server: ".substr($ersponse, 0, 1)); } } @@ -128,7 +128,7 @@ protected function connect() if ($this->connection === false) { - throw new \Exception("Error making Redis connection: {$error} - {$message}"); + throw new \RuntimeException("Error making Redis connection: {$error} - {$message}"); } return $this->connection; @@ -261,4 +261,4 @@ public function __destruct() fclose($this->connection); } -} \ No newline at end of file +} diff --git a/laravel/routing/controller.php b/laravel/routing/controller.php index afbc4d40..2392635b 100644 --- a/laravel/routing/controller.php +++ b/laravel/routing/controller.php @@ -39,7 +39,7 @@ public static function call($destination, $parameters = array()) { if (strpos($destination, '@') === false) { - throw new \Exception("Route delegate [{$destination}] has an invalid format."); + throw new \InvalidArgumentException("Route delegate [{$destination}] has an invalid format."); } list($controller, $method) = explode('@', $destination); @@ -226,7 +226,7 @@ public function __get($key) return IoC::resolve($key); } - throw new \Exception("Attempting to access undefined property [$key] on controller."); + throw new \OutOfBoundsException("Attempting to access undefined property [$key] on controller."); } } diff --git a/laravel/routing/route.php b/laravel/routing/route.php index 230aa2d2..9777a952 100644 --- a/laravel/routing/route.php +++ b/laravel/routing/route.php @@ -63,7 +63,7 @@ public function __construct($key, $callback, $parameters = array()) if ( ! $callback instanceof Closure and ! is_array($callback) and ! is_string($callback)) { - throw new \Exception('Invalid route defined for URI ['.$this->key.']'); + throw new \InvalidArgumentException('Invalid route defined for URI ['.$this->key.']'); } } @@ -226,7 +226,7 @@ public function __call($method, $parameters) return $this->is(substr($method, 3)); } - throw new \Exception("Call to undefined method [$method] on Route class."); + throw new \BadMethodCallException("Call to undefined method [$method] on Route class."); } -} \ No newline at end of file +} diff --git a/laravel/session/drivers/factory.php b/laravel/session/drivers/factory.php index 02abf247..d8fdd625 100644 --- a/laravel/session/drivers/factory.php +++ b/laravel/session/drivers/factory.php @@ -33,8 +33,8 @@ public static function make($driver) return new Redis(Cache::driver('redis')); default: - throw new \Exception("Session driver [$driver] is not supported."); + throw new \DomainException("Session driver [$driver] is not supported."); } } -} \ No newline at end of file +} diff --git a/laravel/session/payload.php b/laravel/session/payload.php index d045e2a8..2bf7a664 100644 --- a/laravel/session/payload.php +++ b/laravel/session/payload.php @@ -10,7 +10,7 @@ if (Config::$items['application']['key'] === '') { - throw new \Exception("An application key is required to use sessions."); + throw new \LogicException("An application key is required to use sessions."); } class Payload { @@ -296,4 +296,4 @@ protected function cookie() Cookie::put($cookie, $this->session['id'], $minutes, $path, $domain, $secure); } -} \ No newline at end of file +} diff --git a/laravel/str.php b/laravel/str.php index fcb05bea..c7efbdc6 100644 --- a/laravel/str.php +++ b/laravel/str.php @@ -196,8 +196,8 @@ protected static function pool($type) return '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; default: - throw new \Exception("Invalid random string type [$type]."); + throw new \DomainException("Invalid random string type [$type]."); } } -} \ No newline at end of file +} diff --git a/laravel/url.php b/laravel/url.php index 1b240312..6c96aedb 100644 --- a/laravel/url.php +++ b/laravel/url.php @@ -115,7 +115,7 @@ public static function to_route($name, $parameters = array(), $https = false) return static::to(str_replace(array('/(:any?)', '/(:num?)'), '', $uri), $https); } - throw new \Exception("Error generating named route for route [$name]. Route is not defined."); + throw new \OutOfBoundsException("Error generating named route for route [$name]. Route is not defined."); } /** @@ -186,7 +186,7 @@ public static function __callStatic($method, $parameters) return static::to_route(substr($method, 3), $parameters); } - throw new \Exception("Method [$method] is not defined on the URL class."); + throw new \BadMethodCallException("Method [$method] is not defined on the URL class."); } -} \ No newline at end of file +} diff --git a/laravel/validator.php b/laravel/validator.php index 3b00d3e5..bf6259f3 100644 --- a/laravel/validator.php +++ b/laravel/validator.php @@ -683,7 +683,7 @@ public function __call($method, $parameters) return call_user_func_array(static::$validators[$method], $parameters); } - throw new \Exception("Call to undefined method [$method] on Validator instance."); + throw new \BadMethodCallException("Call to undefined method [$method] on Validator instance."); } -} \ No newline at end of file +} diff --git a/laravel/view.php b/laravel/view.php index 2633f975..bc3eefcd 100644 --- a/laravel/view.php +++ b/laravel/view.php @@ -87,7 +87,7 @@ protected function path($view) } } - throw new \Exception("View [$view] does not exist."); + throw new \RuntimeException("View [$view] does not exist."); } /** @@ -138,7 +138,7 @@ public static function of($name, $data = array()) return static::make($view, $data); } - throw new \Exception("Named view [$name] is not defined."); + throw new \OutOfBoundsException("Named view [$name] is not defined."); } /** @@ -352,4 +352,4 @@ public static function __callStatic($method, $parameters) } } -} \ No newline at end of file +}