This is documentation for Kohana v2.3.x.
Status | Draft |
---|---|
Todo | triggering errors |
See Kohana logging methods for information on accessing log files.
In the index.php file there is a setting display_errors. This determines whether errors should be outputted to the screen or not. During development you'd want to set this to TRUE, but in production set this to FALSE so as to prevent users from seeing errors. This won't affect logging of errors.
Exceptions in Kohana are handled by the Kohana Exception classes. There are three types of exceptions: Kohana_Exception, Kohana_User_Exception and Kohana_404_Exception.
Kohana_Exception
extends Exception
. To throw a Kohana_Exception
an i18n language file must exist.
/** * @param string i18n language key for the message * @param array addition line parameters */ throw new Kohana_Exception(string $i18_lang_key [, string $message]);
//... if($x == 0) throw new Kohana_Exception('math.division_by_zero'); // Throw a $lang['division_by_zero'] exception in ./i18n/en_US/math.php // "Cannot divide by zero." else if($x < 0) throw new Kohana_Exception('general.math.negative_number', $x); // Throw a $lang['math']['negative_number'] exception in ./i18n/en_US/general.php and pass the message $x // "The number passed was negative: -5" //...
Kohana_User_Exception
extends the Kohana_Exception
. This is similar to Kohana_Exception
except that the exception messages do not have to be in the i18n structure.
/** * @param string exception title string * @param string exception message string * @param string custom error template */ throw new Kohana_User_Exception(string $title, string $message [, string $template]);
//... if($x == 0) throw new Kohana_User_Exception('Cannot divide by zero', 'You passed a zero'); else if($x < 0) throw new Kohana_User_Exception('Number Type Exception', "Cannot use a negative number $x"); //...
Kohana_404_Exception
extends Kohana_Exception
. This exception will display a 404 error message to the user.
/** * @param string URL of page * @param string custom error template */ throw new Kohana_404_Exception([string $page [, string $template]]);
//... if($x == 0) throw new Kohana_404_Exception('divide by zero'); // "The page you requested, Cannot divide by zero, could not be found." //...
The system/views/kohana_error_page.php
is the default error page. You can overload this one by having a kohana_error_page.php
in your application/views
directory or in a similar modules directory.
The default error page will show you the error as well as a stack trace if available.
Kohana can log errors, alerts, info and debugging messages. The setting can be found in application/config/config.php
See Logging for more information.