<commit_before>Error Handling
==============

Yii provides a complete error handling framework based on the PHP 5
exception mechanism. When the application is created to handle an incoming
user request, it registers its [handleError|CApplication::handleError]
method to handle PHP warnings and notices; and it registers its
[handleException|CApplication::handleException] method to handle uncaught
PHP exceptions. Consequently, if a PHP warning/notice or an uncaught
exception occurs during the application execution, one of the error
handlers will take over the control and start the necessary error handling
procedure.

> Tip: The registration of error handlers is done in the application's
constructor by calling PHP functions
[set_exception_handler](http://www.php.net/manual/en/function.set-exception-handler.php)
and [set_error_handler](http://www.php.net/manual/en/function.set-error-handler.php).
If you do not want Yii to handle the errors and exceptions, you may define
constant `YII_ENABLE_ERROR_HANDLER` and `YII_ENABLE_EXCEPTION_HANDLER` to
be false in the [entry script](/doc/guide/basics.entry).

By default, [handleError|CApplication::handleError] (or
[handleException|CApplication::handleException]) will raise an
[onError|CApplication::onError] event (or
[onException|CApplication::onException] event). If the error (or exception)
is not handled by any event handler, it will call for help from the
[errorHandler|CErrorHandler] application component.

Raising Exceptions
------------------

Raising exceptions in Yii is not different from raising a normal PHP
exception. One uses the following syntax to raise an exception when needed:

~~~
[php]
throw new ExceptionClass('ExceptionMessage');
~~~

Yii defines two exception classes: [CException] and [CHttpException]. The
former is a generic exception class, while the latter represents an
exception that should be displayed to end users. The latter also carries a
[statusCode|CHttpException::statusCode] property representing an HTTP
status code. The class of an exception determines how it should be
displayed, as we will explain next.

> Tip: Raising a [CHttpException] exception is a simple way of reporting
errors caused by user misoperation. For example, if the user provides an
invalid post ID in the URL, we can simply do the following to show a 404
error (page not found):
~~~
[php]
// if post ID is invalid
throw new CHttpException(404,'The specified post cannot be found.');
~~~

Displaying Errors
-----------------

When an error is forwarded to the [CErrorHandler] application component,
it chooses an appropriate view to display the error. If the error is meant
to be displayed to end users, such as a [CHttpException], it will use a
view named `errorXXX`, where `XXX` stands for the HTTP status code (e.g.
400, 404, 500). If the error is an internal one and should only be<commit_msg>(Fixes issue 2698) Mentioned CDbException in error handling guide<commit_after>Error Handling
==============

Yii provides a complete error handling framework based on the PHP 5
exception mechanism. When the application is created to handle an incoming
user request, it registers its [handleError|CApplication::handleError]
method to handle PHP warnings and notices; and it registers its
[handleException|CApplication::handleException] method to handle uncaught
PHP exceptions. Consequently, if a PHP warning/notice or an uncaught
exception occurs during the application execution, one of the error
handlers will take over the control and start the necessary error handling
procedure.

> Tip: The registration of error handlers is done in the application's
constructor by calling PHP functions
[set_exception_handler](http://www.php.net/manual/en/function.set-exception-handler.php)
and [set_error_handler](http://www.php.net/manual/en/function.set-error-handler.php).
If you do not want Yii to handle the errors and exceptions, you may define
constant `YII_ENABLE_ERROR_HANDLER` and `YII_ENABLE_EXCEPTION_HANDLER` to
be false in the [entry script](/doc/guide/basics.entry).

By default, [handleError|CApplication::handleError] (or
[handleException|CApplication::handleException]) will raise an
[onError|CApplication::onError] event (or
[onException|CApplication::onException] event). If the error (or exception)
is not handled by any event handler, it will call for help from the
[errorHandler|CErrorHandler] application component.

Raising Exceptions
------------------

Raising exceptions in Yii is not different from raising a normal PHP
exception. One uses the following syntax to raise an exception when needed:

~~~
[php]
throw new ExceptionClass('ExceptionMessage');
~~~

Yii defines three exception classes: [CException], [CDbException] and
[CHttpException]. [CException] is a generic exception class. [CDbException]
represents an exception that is caused by some DB-related operations.
[CHttpException] represents an exception that should be displayed to end users
and carries a [statusCode|CHttpException::statusCode] property representing an HTTP
status code. The class of an exception determines how it should be
displayed, as we will explain next.

> Tip: Raising a [CHttpException] exception is a simple way of reporting
errors caused by user misoperation. For example, if the user provides an
invalid post ID in the URL, we can simply do the following to show a 404
error (page not found):
~~~
[php]
// if post ID is invalid
throw new CHttpException(404,'The specified post cannot be found.');
~~~

Displaying Errors
-----------------

When an error is forwarded to the [CErrorHandler] application component,
it chooses an appropriate view to display the error. If the error is meant
to be displayed to end users, such as a [CHttpException], it will use a
view named `errorXXX`, where `XXX` stands for the HTTP status code (e.g.
400, 404, 500). If the error is an internal one and should only be
{'fraction_non_alphanumeric': 0.08063967335828513, 'fraction_numerical': 0.006124532153793808, 'mean_word_length': 5.1367432150313155, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '330305', 'n_tokens_mistral': 1539, 'n_tokens_neox': 1467, 'n_words': 754}