Yii Error Handling

Facebook Twitter

Error Handling. Yii provides a complete error handling framework based on the PHP 5 exception mechanism.

Error Handling

When the application is created to handle an incoming user request, it registers its handleError method to handle PHP warnings and notices; and it registers its 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 and set_error_handler. 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. By default, handleError (or handleException) will raise an onError event (or onException event). 1. Throw new ExceptionClass('ExceptionMessage');

CException. Catching ALL db-related exception. Y!!

Catching ALL db-related exception

, on 01 February 2011 - 01:11 PM, said: You can do everything within the handler, i.e. accessing Yii::app() without problems. The idea, you provided, seems to be great! :] I do have PHP 5.3.1 but even so I'm using the older method of attaching onException event handler. But I don't know what to do next, when my private handler actually handles the exception? EDIT: I also tried throw new CHttpException, which I used in old approach (handling exceptions through onBeginRequest) but now it only outputs this as a bulk test (like I would use die()) without error view and page layout. To make thing more clear, what I need. Exceptions. Extending Exceptions PHP 5 has an exception model similar to that of other programming languages.


An exception can be thrown, and caught ("catched") within PHP. Code may be surrounded in a try block, to facilitate the catching of potential exceptions. Each try must have at least one corresponding catch block. Multiple catch blocks can be used to catch different classes of exceptions. When an exception is thrown, code following the statement will not be executed, and PHP will attempt to find the first matching catch block.

In PHP 5.5 and later, a finally block may also be specified after the catch blocks. The thrown object must be an instance of the Exception class or a subclass of Exception. Note: Internal PHP functions mainly use Error reporting, only modern Object oriented extensions use exceptions. Example #1 Throwing an Exception <? // Continue executionecho "Hello World\n";? The above example will output: 0.2 Caught exception: Division by zero. 0.2 First finally. <? Johan ¶ 3 years ago ? Exception. When you are using xdebug, exceptions message will never be shown if you use any encoding different than UTF-8, so if you are using any database with translated messages like oracle, you should ALWAYS, always, throw a exception like this throw new Exception(utf8_encode($message),$code), character like ã,é,ç, will make the exception message fail to be shown, if you are not using xdebug ( I do think you should at least try), this code will not affect your page.