Commit 8b803fd3 authored by Taylor Otwell's avatar Taylor Otwell

Merge pull request #156 from sparksp/develop/exception

Better Exceptions
parents bdbdd05b 662bde85
...@@ -303,12 +303,12 @@ class Asset_Container { ...@@ -303,12 +303,12 @@ class Asset_Container {
if ($dependency === $asset) 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'])) 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
...@@ -65,7 +65,7 @@ class Manager { ...@@ -65,7 +65,7 @@ class Manager {
return new Drivers\Redis(Redis::db()); return new Drivers\Redis(Redis::db());
default: default:
throw new \Exception("Cache driver {$driver} is not supported."); throw new \DomainException("Cache driver {$driver} is not supported.");
} }
} }
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
if (trim(Config::$items['application']['key']) === '') 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 { class Cookie {
...@@ -128,4 +128,4 @@ class Cookie { ...@@ -128,4 +128,4 @@ class Cookie {
return static::put($name, null, -2000); return static::put($name, null, -2000);
} }
} }
\ No newline at end of file
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
if (trim(Config::$items['application']['key']) === '') 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 { class Crypter {
...@@ -62,7 +62,7 @@ class Crypter { ...@@ -62,7 +62,7 @@ class Crypter {
{ {
if (($value = base64_decode($value)) === false) 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()); $iv = substr($value, 0, static::iv_size());
...@@ -92,4 +92,4 @@ class Crypter { ...@@ -92,4 +92,4 @@ class Crypter {
return Config::$items['application']['key']; return Config::$items['application']['key'];
} }
} }
\ No newline at end of file
...@@ -52,7 +52,7 @@ class SQLite extends Connector { ...@@ -52,7 +52,7 @@ class SQLite extends Connector {
return new PDO('sqlite:'.$config['database'], null, null, $options); 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
...@@ -18,7 +18,7 @@ class Hydrator { ...@@ -18,7 +18,7 @@ class Hydrator {
{ {
if ( ! method_exists($eloquent, $include)) 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); static::eagerly($eloquent, $results, $include);
...@@ -209,4 +209,4 @@ class Hydrator { ...@@ -209,4 +209,4 @@ class Hydrator {
} }
} }
} }
\ No newline at end of file
...@@ -38,7 +38,7 @@ class Manager { ...@@ -38,7 +38,7 @@ class Manager {
if (is_null($config)) 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); static::$connections[$connection] = new Connection(static::connect($config), $config);
...@@ -88,7 +88,7 @@ class Manager { ...@@ -88,7 +88,7 @@ class Manager {
return new Connectors\Postgres; return new Connectors\Postgres;
default: default:
throw new \Exception("Database driver [$driver] is not supported."); throw new \DomainException("Database driver [$driver] is not supported.");
} }
} }
...@@ -127,4 +127,4 @@ class Manager { ...@@ -127,4 +127,4 @@ class Manager {
return call_user_func_array(array(static::connection(), $method), $parameters); return call_user_func_array(array(static::connection(), $method), $parameters);
} }
} }
\ No newline at end of file
...@@ -669,7 +669,7 @@ class Query { ...@@ -669,7 +669,7 @@ class Query {
} }
} }
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
...@@ -376,7 +376,7 @@ class HTML { ...@@ -376,7 +376,7 @@ class HTML {
return forward_static_call_array('HTML::link_to_route', $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
...@@ -123,7 +123,7 @@ class Input { ...@@ -123,7 +123,7 @@ class Input {
{ {
if (Config::get('session.driver') == '') 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()); $old = IoC::core('session')->get(Input::old_input, array());
......
...@@ -145,7 +145,7 @@ class IoC { ...@@ -145,7 +145,7 @@ class IoC {
if ( ! static::registered($name)) 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); $object = call_user_func(static::$registry[$name]['resolver'], $parameters);
...@@ -165,4 +165,4 @@ class IoC { ...@@ -165,4 +165,4 @@ class IoC {
* loaded since there isn't any reason to load the container * loaded since there isn't any reason to load the container
* configuration until the class is first requested. * configuration until the class is first requested.
*/ */
IoC::bootstrap(); IoC::bootstrap();
\ No newline at end of file
...@@ -149,7 +149,7 @@ class Lang { ...@@ -149,7 +149,7 @@ class Lang {
return array($segments[0], implode('.', array_slice($segments, 1))); 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 @@ class Lang { ...@@ -188,4 +188,4 @@ class Lang {
return $this->get(); return $this->get();
} }
} }
\ No newline at end of file
...@@ -53,10 +53,10 @@ class Memcached { ...@@ -53,10 +53,10 @@ class Memcached {
if ($memcache->getVersion() === false) 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; return $memcache;
} }
} }
\ No newline at end of file
...@@ -56,7 +56,7 @@ class Redirect extends Response { ...@@ -56,7 +56,7 @@ class Redirect extends Response {
{ {
if (Config::get('session.driver') == '') 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); IoC::core('session')->flash($key, $value);
...@@ -91,7 +91,7 @@ class Redirect extends Response { ...@@ -91,7 +91,7 @@ class Redirect extends Response {
return static::to(URL::to_route(substr($method, 3), $parameters), $status); 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.");
} }
} }
...@@ -65,7 +65,7 @@ class Redis { ...@@ -65,7 +65,7 @@ class Redis {
{ {
if (is_null($config = Config::get("database.redis.{$name}"))) 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']); static::$databases[$name] = new static($config['host'], $config['port']);
...@@ -98,7 +98,7 @@ class Redis { ...@@ -98,7 +98,7 @@ class Redis {
switch (substr($ersponse, 0, 1)) switch (substr($ersponse, 0, 1))
{ {
case '-': case '-':
throw new \Exception('Redis error: '.substr(trim($ersponse), 4)); throw new \RuntimeException('Redis error: '.substr(trim($ersponse), 4));
case '+': case '+':
case ':': case ':':
...@@ -111,7 +111,7 @@ class Redis { ...@@ -111,7 +111,7 @@ class Redis {
return $this->multibulk($ersponse); return $this->multibulk($ersponse);
default: 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 @@ class Redis { ...@@ -128,7 +128,7 @@ class Redis {
if ($this->connection === false) 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; return $this->connection;
...@@ -261,4 +261,4 @@ class Redis { ...@@ -261,4 +261,4 @@ class Redis {
fclose($this->connection); fclose($this->connection);
} }
} }
\ No newline at end of file
...@@ -39,7 +39,7 @@ abstract class Controller { ...@@ -39,7 +39,7 @@ abstract class Controller {
{ {
if (strpos($destination, '@') === false) 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); list($controller, $method) = explode('@', $destination);
...@@ -226,7 +226,7 @@ abstract class Controller { ...@@ -226,7 +226,7 @@ abstract class Controller {
return IoC::resolve($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.");
} }
} }
...@@ -63,7 +63,7 @@ class Route { ...@@ -63,7 +63,7 @@ class Route {
if ( ! $callback instanceof Closure and ! is_array($callback) and ! is_string($callback)) 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 @@ class Route { ...@@ -226,7 +226,7 @@ class Route {
return $this->is(substr($method, 3)); 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
...@@ -33,8 +33,8 @@ class Factory { ...@@ -33,8 +33,8 @@ class Factory {
return new Redis(Cache::driver('redis')); return new Redis(Cache::driver('redis'));
default: 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
...@@ -10,7 +10,7 @@ use Laravel\Session\Drivers\Sweeper; ...@@ -10,7 +10,7 @@ use Laravel\Session\Drivers\Sweeper;
if (Config::$items['application']['key'] === '') 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 { class Payload {
...@@ -296,4 +296,4 @@ class Payload { ...@@ -296,4 +296,4 @@ class Payload {
Cookie::put($cookie, $this->session['id'], $minutes, $path, $domain, $secure); Cookie::put($cookie, $this->session['id'], $minutes, $path, $domain, $secure);
} }
} }
\ No newline at end of file
...@@ -196,8 +196,8 @@ class Str { ...@@ -196,8 +196,8 @@ class Str {
return '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; return '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
default: default:
throw new \Exception("Invalid random string type [$type]."); throw new \DomainException("Invalid random string type [$type].");
} }
} }
} }
\ No newline at end of file
...@@ -115,7 +115,7 @@ class URL { ...@@ -115,7 +115,7 @@ class URL {
return static::to(str_replace(array('/(:any?)', '/(:num?)'), '', $uri), $https); 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 @@ class URL { ...@@ -186,7 +186,7 @@ class URL {
return static::to_route(substr($method, 3), $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
...@@ -683,7 +683,7 @@ class Validator { ...@@ -683,7 +683,7 @@ class Validator {
return call_user_func_array(static::$validators[$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
...@@ -87,7 +87,7 @@ class View { ...@@ -87,7 +87,7 @@ class View {
} }
} }
throw new \Exception("View [$view] does not exist."); throw new \RuntimeException("View [$view] does not exist.");
} }
/** /**
...@@ -138,7 +138,7 @@ class View { ...@@ -138,7 +138,7 @@ class View {
return static::make($view, $data); 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 @@ class View { ...@@ -352,4 +352,4 @@ class View {
} }
} }
} }
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment