Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Sign in
Toggle navigation
S
Silex
Project overview
Project overview
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Commits
Open sidebar
common
Silex
Commits
34dbfea8
Commit
34dbfea8
authored
Jul 21, 2011
by
Fabien Potencier
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added a tip in the documentation about error handling
parent
0c67f90c
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
18 additions
and
7 deletions
+18
-7
doc/usage.rst
doc/usage.rst
+18
-7
No files found.
doc/usage.rst
View file @
34dbfea8
...
@@ -354,13 +354,6 @@ If some part of your code throws an exception you will want to display
...
@@ -354,13 +354,6 @@ If some part of your code throws an exception you will want to display
some kind of error page to the user. This is what error handlers do. You
some kind of error page to the user. This is what error handlers do. You
can also use them to do additional things, such as logging.
can also use them to do additional things, such as logging.
.. note::
Silex comes with a default error handler that displays a detailed error
message with the stack trace when **debug** is true, and a simple error
message otherwise. Error handlers registered via the ``error()`` method
always take precedence.
To register an error handler, pass a closure to the ``error`` method
To register an error handler, pass a closure to the ``error`` method
which takes an ``Exception`` argument and returns a response::
which takes an ``Exception`` argument and returns a response::
...
@@ -396,6 +389,24 @@ once a response is returned, the following handlers are ignored.
...
@@ -396,6 +389,24 @@ once a response is returned, the following handlers are ignored.
which handles logging of errors. Check out the *Extensions* chapter
which handles logging of errors. Check out the *Extensions* chapter
for details.
for details.
.. tip::
Silex comes with a default error handler that displays a detailed error
message with the stack trace when **debug** is true, and a simple error
message otherwise. Error handlers registered via the ``error()`` method
always take precedence but you can keep the nice error messages when debug
is turned on like this::
use Symfony\Component\HttpFoundation\Response;
$app->error(function (\Exception $e, $code) {
if ($app['debug']) {
return;
}
// logic to handle the error and return a Response
});
Redirects
Redirects
---------
---------
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment