Scaffold/Scaffold — pull request #45 by nathggns (2012-12-27 15:37:04+00:00)
Title: Error class

Easily handle errors on both a global and local scale.

To handle errors globally, there is absolutely nothing you need to do in system code.

Attaching to a global error is easy. To catch 404, you would do this in `application/bootstrap.php`

```php
attach('ExceptionRouting', function($obj) {
// Catch the exception
$obj->catch();

// Send output?
$obj->send('404', 404);
});
```

To attach an error handler on a local scale, we do something called aliasing. Because of PHP's scoping system, you actually have to catch the exception yourself, but then you can pass it into the error system straight away.

```php
handle($e);
}

Service::get('error', 'test')->attach('Exception', function($obj) {
// ...
})
```

The `$obj` variable has many purposes.

```php
catch();

// Rethrow the exception
$obj->rethrow();

// Don't run any other handlers
$obj->stop();

// Send data
$obj->send($data, $http_code = 200);
```

Couple of things to think about

* You have to manually catch exceptions from within handlers.
* No way to define the '500 Internal Server Error' response from within application bootstrap.