Today we are going to understand the error handling especially in CI in this Error Handling in CodeIgniter tutorial.
PHP has various levels of error reporting for different errors. What level of error we get when we run our script depends on our server configuration. The decision to show the error on screen or not, is controlled by the server setting called display_errors. The developer may or may not have access to the underlying server setting such as display_errors. So the underlying settings are unknown to us. These settings are made known to us by codeigniter by the use of error_reporting() function on every page call, which overrides the settings of display_errors. This error_reporting() is found in the main index.php file.
Error functions in codeigniter are simple procedural interfaces that are available globally throughout the application, hence the error messages are triggered without caring about the class/function scope.
CodeIgniter helps us to report errors into our applications by using the following functions:
- This function displays the error message using the template in application/errors/error_general.php.
- Syntax of show_error() function is:
show_error(‘File not found!’);
- This function displays the 404 error message supplied to it by the template in application/errors/error_404.php.
- Syntax of show_404() function is:
- Everytime a page is run, a log file is generated. These log files are under developer’s control.
- This function allows you to write messages in the log file.
- Syntax of log_message() function is:
log_message(‘error’,’username is empty’);