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
d272d710
Commit
d272d710
authored
Dec 12, 2012
by
Igor Wiedler
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[docs] Add cookbook recipe for the ErrorHandler
parent
0e69dc22
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
39 additions
and
0 deletions
+39
-0
doc/cookbook/error_handler.rst
doc/cookbook/error_handler.rst
+36
-0
doc/cookbook/index.rst
doc/cookbook/index.rst
+3
-0
No files found.
doc/cookbook/error_handler.rst
0 → 100644
View file @
d272d710
How to convert errors to exceptions
===================================
Silex will catch exceptions that are thrown from within a request/response
cycle. It will however *not* catch PHP errors and notices. You can catch them
by converting them to exceptions, this recipe will tell you how.
Why does Silex not do this?
---------------------------
Silex could do this automatically in theory, but there is a reason why it does
not. Silex acts as a library, this means that it does not mess with any global
state. Since error handlers are global in PHP, it is your responsibility as a
user to register them.
Registering the ErrorHandler
----------------------------
Fortunately, Silex ships with an ``ErrorHandler`` (it's part of the
``HttpKernel`` package) that solves this issue. It converts all errors to
exceptions, and exceptions can be caught by Silex.
You register it by calling the static ``register`` method::
use Symfony\Component\HttpKernel\Debug\ErrorHandler;
ErrorHandler::register();
It is recommended that you do this in your front controller, i.e.
``web/index.php``.
.. note::
The ``ErrorHandler`` has nothing to do with the ``ExceptionHandler``. The
``ExceptionHandler`` is responsible for displaying caught exceptions
nicely.
doc/cookbook/index.rst
View file @
d272d710
...
@@ -13,6 +13,7 @@ The cookbook section contains recipes for solving specific problems.
...
@@ -13,6 +13,7 @@ The cookbook section contains recipes for solving specific problems.
form_no_csrf
form_no_csrf
validator_yaml
validator_yaml
sub_requests
sub_requests
error_handler
Recipes
Recipes
-------
-------
...
@@ -32,3 +33,5 @@ Recipes
...
@@ -32,3 +33,5 @@ Recipes
* :doc:`How to use YAML to configure validation <validator_yaml>`.
* :doc:`How to use YAML to configure validation <validator_yaml>`.
* :doc:`How to make sub-requests <sub_requests>`.
* :doc:`How to make sub-requests <sub_requests>`.
* :doc:`How to convert errors to exceptions <error_handler>`.
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