Commit 58638216 authored by Phill Sparks's avatar Phill Sparks

Throw better Exceptions

parent d643ec97
......@@ -303,11 +303,11 @@ class Asset_Container {
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.");
}
}
......
......@@ -65,7 +65,7 @@ class Manager {
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.");
}
}
......
......@@ -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 {
......
......@@ -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 @@ class Crypter {
{
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());
......
......@@ -52,7 +52,7 @@ class SQLite extends Connector {
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.");
}
}
......@@ -18,7 +18,7 @@ class Hydrator {
{
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);
......
......@@ -38,7 +38,7 @@ class Manager {
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 @@ class Manager {
return new Connectors\Postgres;
default:
throw new \Exception("Database driver [$driver] is not supported.");
throw new \DomainException("Database driver [$driver] is not supported.");
}
}
......
......@@ -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.");
}
}
......@@ -376,7 +376,7 @@ class HTML {
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.");
}
}
......@@ -123,7 +123,7 @@ class Input {
{
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());
......
......@@ -145,7 +145,7 @@ class IoC {
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);
......
......@@ -149,7 +149,7 @@ class Lang {
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.");
}
/**
......
......@@ -53,7 +53,7 @@ class Memcached {
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;
......
......@@ -56,7 +56,7 @@ class Redirect extends Response {
{
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 @@ class Redirect extends Response {
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 {
{
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 @@ class Redis {
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 @@ class Redis {
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 @@ class Redis {
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;
......
......@@ -39,7 +39,7 @@ abstract class Controller {
{
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 @@ abstract class Controller {
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 {
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 {
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.");
}
}
......@@ -33,7 +33,7 @@ class Factory {
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.");
}
}
......
......@@ -10,7 +10,7 @@ use Laravel\Session\Drivers\Sweeper;
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 {
......
......@@ -196,7 +196,7 @@ class Str {
return '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
default:
throw new \Exception("Invalid random string type [$type].");
throw new \DomainException("Invalid random string type [$type].");
}
}
......
......@@ -115,7 +115,7 @@ class URL {
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 {
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.");
}
}
......@@ -683,7 +683,7 @@ class Validator {
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.");
}
}
......@@ -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 {
return static::make($view, $data);
}
throw new \Exception("Named view [$name] is not defined.");
throw new \OutOfBoundsException("Named view [$name] is not defined.");
}
/**
......
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