nathggns / Scaffold

Lightweight PHP API Framework
Other
8 stars 2 forks source link

Router Exception Handler #41

Closed nathggns closed 11 years ago

nathggns commented 11 years ago

Somehow we need to handle exceptions.

I propose a system similar to this.

I propose an exception handler sort of system.

Single Exception

<?php
$router->error('ExceptionValidate', function($e) {
    // ...
});

Multiple Exceptions

<?php
$router->error(['ExceptionValidate', 'ExceptionRouting'], function($e) {
    // ...
});

All Exceptions

<?php
$router->error(true, function($e) {
    // ..
});

Where $e is an object allowing you to decide what to do.

<?php
$e->rethrow();  // Re-throw the error. (Eventually this will be catched by the Error class, which is yet to be made.
$e->send($val); // Send value.
$e->exc // The actual exception
nathggns commented 11 years ago

This solves #40.

nathggns commented 11 years ago

Also, $e->type for the type of error it was, such as ExceptionRouting.

nathggns commented 11 years ago

Something to think about: Is the 'true for all exceptions' needed, cause you could just pass Exception?