Skip to content

Commit 5358b14

Browse files
committed
docs: add user guide
1 parent eff6b99 commit 5358b14

File tree

3 files changed

+50
-5
lines changed

3 files changed

+50
-5
lines changed

user_guide_src/source/changelogs/v4.3.0.rst

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,20 @@ Exceptions when Database Errors Occur
2323
- 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``.
2424
- 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``.
2525

26+
HTTP Status Code and Exit Code when Exception Occurs
27+
----------------------------------------------------
28+
29+
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``.
39+
2640
Others
2741
------
2842

user_guide_src/source/general/errors.rst

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,10 @@ To ignore logging on other status codes, you can set the status code to ignore i
6464
.. note:: It is possible that logging still will not happen for exceptions if your current Log settings
6565
are not set up to log **critical** errors, which all exceptions are logged as.
6666

67-
Custom Exceptions
68-
=================
67+
Framework Exceptions
68+
====================
6969

70-
The following custom exceptions are available:
70+
The following framework exceptions are available:
7171

7272
PageNotFoundException
7373
---------------------
@@ -89,7 +89,7 @@ is not the right type, etc:
8989

9090
.. literalinclude:: errors/008.php
9191

92-
This provides an HTTP status code of 500 and an exit code of 3.
92+
This provides an exit code of 3.
9393

9494
DatabaseException
9595
-----------------
@@ -99,7 +99,7 @@ or when it is temporarily lost:
9999

100100
.. literalinclude:: errors/009.php
101101

102-
This provides an HTTP status code of 500 and an exit code of 8.
102+
This provides an exit code of 8.
103103

104104
RedirectException
105105
-----------------
@@ -113,3 +113,23 @@ forcing a redirect to a specific route or URL:
113113
redirect code to use instead of the default (``302``, "temporary redirect"):
114114

115115
.. 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.

user_guide_src/source/installation/upgrade_430.rst

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,17 @@ Add **types** to the properties in these Config classes. You may need to fix the
4444
Breaking Changes
4545
****************
4646

47+
HTTP Status Code and Exit Code of Uncaught Exceptions
48+
=====================================================
49+
50+
- 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+
4758
- 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.
4859

4960
Breaking Enhancements

0 commit comments

Comments
 (0)