Blog

Joomla Exceptions

Joomla Exceptions! Another piece of the puzzle.

Starting Joomla can be frustrating.. Especially when you may be use to another framework or style of coding... Thoughts run through your mind, "What is Joomla's equivalent method!".

If you are trying to prevent people from accessing pages that you create. One of the ways to do that is by throwing an exception. Most of the time you want to prevent people from entering in bad urls.

Yoursite.com/index.php?my_content_id=apple

Most likely you do not want to accept apple as an id parameter. This can be solved by throwing an exception if valid content is not retrieved from "my_content_id=apple"

So how do you handle Exceptions?
Using or customizing the exception page under templates/system/error.phpThrowing an exception: JError::raiseError( 404, JText::_('ALERTNOTAUTH') );You can be fancy and create a function to throw dynamic errors from this if you wish. It would be best if you put this function in some sort of static method site-wide, but I still haven't found a way to create site-wide custom classes or libraries (e.g. JSite, JRequest, etc)

Our Latest Tweets