You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: user_guide_src/source/changelogs/v4.3.0.rst
+14Lines changed: 14 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -23,6 +23,20 @@ Exceptions when Database Errors Occur
23
23
- The exceptions thrown by the database connection classes have been changed to ``CodeIgniter\Database\Exceptions\DatabaseException``. Previously, different database drivers threw different exception classes, but these have been unified into ``DatabaseException``.
24
24
- The exceptions thrown by the ``execute()`` method of Prepared Queries have been changed to ``DatabaseException``. Previously, different database drivers might throw different exception classes or did not throw exceptions, but these have been unified into ``DatabaseException``.
25
25
26
+
HTTP Status Code and Exit Code when Exception Occurs
Previously, the CodeIgniter's Exception Handler used the *Exception code* as *HTTP status code* in some cases, and set calculated *Exit code* based on the Exception code. However there is essentially nothing to do with Exception code and HTTP Status Code or Exit code.
30
+
31
+
- Now the Exception Handler sets HTTP status code to ``500`` and set Exit code to the constant ``EXIT_ERROR`` (= ``1``) by default.
32
+
- You can change HTTP status code or Exit code to implements ``HTTPExceptionInterface`` or ``HasExitCodeInterface`` in your Exception class.
33
+
34
+
For example, the Exit code has been changed like the following:
35
+
36
+
- If an uncaught ``ConfigException`` occurs, the Exit code is ``EXIT_CONFIG`` (= ``3``) instead of ``12``.
37
+
- If an uncaught ``CastException`` occurs, the Exit code is ``EXIT_CONFIG`` (= ``3``) instead of ``9``.
38
+
- If an uncaught ``DatabaseException`` occurs, the Exit code is ``EXIT_DATABASE`` (= ``8``) instead of ``17``.
Copy file name to clipboardExpand all lines: user_guide_src/source/general/errors.rst
+25-5Lines changed: 25 additions & 5 deletions
Original file line number
Diff line number
Diff line change
@@ -64,10 +64,10 @@ To ignore logging on other status codes, you can set the status code to ignore i
64
64
.. note:: It is possible that logging still will not happen for exceptions if your current Log settings
65
65
are not set up to log **critical** errors, which all exceptions are logged as.
66
66
67
-
Custom Exceptions
68
-
=================
67
+
Framework Exceptions
68
+
====================
69
69
70
-
The following custom exceptions are available:
70
+
The following framework exceptions are available:
71
71
72
72
PageNotFoundException
73
73
---------------------
@@ -89,7 +89,7 @@ is not the right type, etc:
89
89
90
90
.. literalinclude:: errors/008.php
91
91
92
-
This provides an HTTP status code of 500 and an exit code of 3.
92
+
This provides an exit code of 3.
93
93
94
94
DatabaseException
95
95
-----------------
@@ -99,7 +99,7 @@ or when it is temporarily lost:
99
99
100
100
.. literalinclude:: errors/009.php
101
101
102
-
This provides an HTTP status code of 500 and an exit code of 8.
102
+
This provides an exit code of 8.
103
103
104
104
RedirectException
105
105
-----------------
@@ -113,3 +113,23 @@ forcing a redirect to a specific route or URL:
113
113
redirect code to use instead of the default (``302``, "temporary redirect"):
114
114
115
115
.. literalinclude:: errors/011.php
116
+
117
+
.. _error-specify-http-status-code:
118
+
119
+
Specify HTTP Status Code in Your Exception
120
+
==========================================
121
+
122
+
Since v4.3.0, you can specify the HTTP status code for your Exception class to implement
123
+
``HTTPExceptionInterface``.
124
+
125
+
When an exception implemented ``HTTPExceptionInterface`` is caught by CodeIgniter's exception handler, the Exception code will be the HTTP status code.
126
+
127
+
.. _error-specify-exit-code:
128
+
129
+
Specify Exit Code in Your Exception
130
+
===================================
131
+
132
+
Since v4.3.0, you can specify the exit code for your Exception class to implement
133
+
``HasExitCodeInterface``.
134
+
135
+
When an exception implemented ``HasExitCodeInterface`` is caught by CodeIgniter's exception handler, the code returned from the ``getExitCode()`` method will be the exit code.
- If you expect *Exception code* as *HTTP status code*, the HTTP status code will be changed.
51
+
In that case, you need to implements ``HTTPExceptionInterface`` in the Exception. See :ref:`error-specify-http-status-code`.
52
+
- If you expect *Exit code* based on *Exception code*, the Exit code will be changed.
53
+
In that case, you need to implements ``HasExitCodeInterface`` in the Exception. See :ref:`error-specify-exit-code`.
54
+
55
+
Others
56
+
======
57
+
47
58
- The exception classes may be changed when database errors occur. If you catch the exceptions, you must confirm that your code can catch the exceptions. See :ref:`exceptions-when-database-errors-occur` for details.
0 commit comments