CodeIgniter Error Handling - CodeIgniter

What is Error Handling in CodeIgniter?

Commonly, while the usage of application, we encounter errors. It is very stressful for the customers if the mistakes aren't handled nicely. CodeIgniter gives an easy error handling mechanism.

You would like the messages to be displayed, while the application is in developing mode instead of in production mode as the error messages may be solved easily on the developing stage.

The environment of your utility can be changed, via changing the line given underneath from index.php file. This could be set to anything but typically there are three values (development, take a look at, production) used for this purpose.

Different surroundings would require different stages of error reporting. By means of default, improvement mode will show mistakes and checking out and live mode will hide them. CodeIgniter provides three capabilities as shown beneath to deal with errors.

  • show_error() function displays errors in HTML format at the top of the screen.


show_error($message, $status_code, $heading = 'An Error Was Encountered')


· $message(mixed) − Error message

· $status_code(int) − HTTP Response status code

· $heading(string) − Error page heading

Return Type


show_404() function displays error if you are trying to access a page which does not exist.


show_404($page = '', $log_error = TRUE)


· $page(string) – URI string

· $log_error(bool) – Whether to log the error

Return Type


  • Log _message () function is used to write log messages. This is useful when you want to write custom messages.


log_message($level, $message, $php_error = FALSE)


· $level(string) − Log level: ‘error’, ‘debug’ or ‘info’

· $message(string) − Message to log

· $php_error(bool) − Whether we’re logging a native PHP error message

Return Type


Logging can be enabled in application/config/config.php file. Given below is the screenshot of config.php file, where you can set threshold value.

You can find the log messages in application/log/. Make sure that this directory is writable before you enable log files.

Various templates for error messages can be found in application/views/errors/cli or application/views/errors/html.

All rights reserved © 2020 Wisdom IT Services India Pvt. Ltd Protection Status

CodeIgniter Topics