Merge pull request #156 from sparksp/develop/exception
Better Exceptions
This commit is contained in:
commit
8b803fd356
|
@ -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.");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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.");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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'];
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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.");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
|||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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.");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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.");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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());
|
||||
|
|
|
@ -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();
|
||||
IoC::bootstrap();
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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.");
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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.");
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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.");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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.");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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].");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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.");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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.");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
|||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue