|
Although just printing error messages suffices for quick and dirty debugging which can be addictive, Joomla provides a fancy mechanism for treating errors. The JError class implements this mechanism and provides certain options like having a log file to keep error messages, or call a routine in case of an error or even force application to die after a fatal error. All these may look distant for now nevertheless we can have a quick look. If you want to make your application to die with an error message, here is the one-liner: JError::raiseError(500, "creeping death"); In our case, we can put in the error case: JError::raiseError(500, $db->getErrorMsg()); Joomla supports a set of error levels and a set of actions to be followed in case of an error. Note that these errors are not related to MySQL errors, you can raise errors any time in your scripts by calling the raiseError, the raiseWarning or the raiseNotice methods of the JError class. The interesting thing is you can correlate error levels to error handling actions. For example, you can send warnings to the application error log files by using: JError::setErrorHandling(E_WARNING, 'log'); Then in your scipt you can use: JError::raiseWarning(500, $db->getErrorMsg()); If the permissions of your /var/www/joomla/logs path are fine, you can find the raised errors in there. Of course, you could assign to the warning level the simple print to browser action with: JError::setErrorHandling(E_WARNING, 'echo'); For now, I am not going to get too much into error levels. I just wanted to be sure that when you come across error handling in the open source modules you read, you won’t be any worried. Having said that, I think we‘ve covered whatever we need to start writing simple modules. To be honest when I first started reading, coding and writing this tutorial, I expected that the journey would be much longer before I am able to produce something. |