Search

Codeigniter  Error Handling

Usually, during the use of the application, we encounter errors. It is very stressful if mistakes are not handled well. CodeIgniter provides an easy error handling mechanism while the application is in developing mode instead of in production mode as the error messages may be solved easily on the developing stage.

By changing the line below from the index.php file, the environment of your application can be changed. It can be set to anything but typically there are three values (development mode, test mode, production mode) used for this purpose.

NOTE: If you want to change these, also change the error_reporting() code below define('ENVIRONMENT', isset($_SERVER['CI_ENV']) ? $_SERVER['CI_ENV'] : 'development');

Different environments will require different levels of error reporting. By default, development mode will display errors and test and production mode will hide them. CodeIgniter provides errors  hide and show as shown below example.

Example :-

error_reporting(-0); ini_set('display_errors', 0); error_reporting(E_ALL & ~E_NOTICE & ~E_DEPRECATED & ~E_STRICT & ~E_USER_NOTICE & ~E_USER_DEPRECATED);

In the above example, the error report is hide

error_reporting(-1); ini_set('display_errors', 1); error_reporting(E_ALL & ~E_NOTICE & ~E_DEPRECATED & ~E_STRICT & ~E_USER_NOTICE & ~E_USER_DEPRECATED);

In the above example, the error report is Show

 

Stack Overlode is optimized Tutorials and examples for learning and training. Examples might be simplified to improve reading and learning and understand. Tutorials and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content. While using Stack Overlode, you agree to have read and accepted our terms of use, cookie and privacy policy.