Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: cakephp/docs
base: 3af47887a1
...
head fork: cakephp/docs
compare: 2fbf875ba2
  • 4 commits
  • 2 files changed
  • 0 commit comments
  • 1 contributor
Showing with 40 additions and 3 deletions.
  1. +2 −0  en/appendices/2-2-migration-guide.rst
  2. +38 −3 en/development/errors.rst
View
2  en/appendices/2-2-migration-guide.rst
@@ -34,6 +34,8 @@ Error Handling
- You can now configure application specific console error handling. By setting
``Error.consoleHandler``, and ``Exception.consoleHandler`` you can define the
callback that will handle errors/exceptions raised in console applications.
+- The handler configured in ``Error.handler`` and ``Error.consoleHandler`` will
+ receive fatal error codes (ie. ``E_ERROR``, ``E_PARSE``, ``E_USER_ERROR``).
Network
=======
View
41 en/development/errors.rst
@@ -26,10 +26,10 @@ default error handling configuration looks like::
'trace' => true
));
-You have 4 built-in options when configuring error handlers:
+You have 5 built-in options when configuring error handlers:
* ``handler`` - callback - The callback to handle errors. You can set this to any
- callback type, including anonymous functions.
+ callable type, including anonymous functions.
* ``level`` - int - The level of errors you are interested in capturing. Use the
built-in php error constants, and bitmasks to select the level of error you
are interested in.
@@ -42,6 +42,8 @@ You have 4 built-in options when configuring error handlers:
ErrorHandler by default, displays errors when ``debug`` > 0, and logs errors when
debug = 0. The type of errors captured in both cases is controlled by ``Error.level``.
+The fatal error handler will be called independent of ``debug`` level or ``Error.level``
+configuration, but the result will be different based on ``debug`` level.
.. note::
@@ -51,6 +53,11 @@ debug = 0. The type of errors captured in both cases is controlled by ``Error.l
.. versionadded:: 2.2
The ``Error.consoleHandler`` option was added in 2.2.
+.. versionmodified:: 2.2
+ The ``Error.handler`` and ``Error.consoleHandler`` will receive the fatal error
+ codes as well. The default behavior is show a page to internal server error
+ (``debug`` disabled) or a page with the message, file and line (``debug`` enabled).
+
Creating your own error handler
===============================
@@ -86,6 +93,34 @@ errors, and that if you need custom error handling, you probably also want to co
:doc:`/development/exceptions` handling as well.
+Changing fatal error behavior
+=============================
+
+Since CakePHP 2.2 the ``Error.handler`` will recieve the fatal error codes as well.
+If you do not want to show the cake error page, you can override it like::
+
+ <?php
+ //in app/Config/core.php
+ Configure::write('Error.handler', 'AppError::handleError');
+
+ //in app/Config/bootstrap.php
+ App::uses('AppError', 'Lib');
+
+ //in app/Lib/AppError.php
+ class AppError {
+ public static function handleError($code, $description, $file = null, $line = null, $context = null) {
+ list(, $level) = ErrorHandler::mapErrorCode($code);
+ if ($level === LOG_ERROR) {
+ // Ignore fatal error. It will keep the PHP error message only
+ return false;
+ }
+ return ErrorHandler::handleError($code, $description, $file, $line, $context);
+ }
+ }
+
+If you want to keep the default fatal error behavior, you can call ``ErrorHandler::handleFatalError()``
+from your custom handler.
+
.. meta::
:title lang=en: Error Handling
- :keywords lang=en: stack traces,error constants,error array,default displays,anonymous functions,error handlers,default error,error level,exception handler,php error,error handler,write error,core classes,exception handling,configuration error,application code,callback,custom error,exceptions,bitmasks
+ :keywords lang=en: stack traces,error constants,error array,default displays,anonymous functions,error handlers,default error,error level,exception handler,php error,error handler,write error,core classes,exception handling,configuration error,application code,callback,custom error,exceptions,bitmasks,fatal error

No commit comments for this range

Something went wrong with that request. Please try again.