2

Today my website showed errors to end users on one page because an image was missing. This is an image stored in jseblod and accessed by using new JImage() in my template.

Is there a guideline on how to handle this error? JImage throws (literally) at least 3 different errors, does this indicate I should simply use try{}catch blocks, or is there a recommended way to handle a missing image

  • Yes, try catch would be a good idea, and then use enqueueMessage to display the error. – Lodder Nov 16 '15 at 9:29
1

Yup, using catching exceptions would be the best idea in my opinion, I'd then use Joomla enqueueMessage function to display a user friend error message, like so:

try
{
    // Try to do something with the image using 'JImage'
}
catch (Exception $e)
{
    // The image was missing
    JFactory::getApplication()->enqueueMessage(JText::_('MISSING_IMAGE'), 'error');

    // Error message = $e->getMessage();
    // I'd then most likely log the actual PHP error to a file using 'JLog'
}

Hope this helps

2

You have a few options, but the easiest solution would be to run an ifexists on the src prior to running the jimage. I.e:

If (JFile::exists($src)) { //Run jimage here }

Alternatively you could add the images to an array and run a for each depending on your output and function.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.