Browse files

Added exception handling example to cookbook

  • Loading branch information...
1 parent 91fce87 commit d776bb2a327c693cb2d5e820aaeb25a59868b37d @peej committed Jul 2, 2012
Showing with 21 additions and 0 deletions.
  1. +21 −0 README.markdown
View
21 README.markdown
@@ -352,6 +352,27 @@ resource and an "object" resource to store within it:
}
+Handling errors
+---------------
+
+When an error occurs, Tonic throws an exception that extends the Tonic\Exception class. You
+can amend the front controller to catch these exceptions and handle them.
+
+ $app = new Tonic\Application();
+ $request = new Tonic\Request();
+ try {
+ $resource = $app->getResource($request);
+ } catch(Tonic\NotFoundException $e) {
+ $resource = new NotFoundResource($app, $request);
+ }
+ try {
+ $response = $resource->exec();
+ } catch(Tonic\Exception $e) {
+ $resource = new FatalErrorResource($app, $request);
+ $response = $resource->exec();
+ }
+ $response->output();
+
For more information, read the code. Start with the dispatcher "web/dispatch.php"

0 comments on commit d776bb2

Please sign in to comment.