JERROR-CLASS-001
JError::raiseError()
JError / JException
JError was Joomla's old error stack. It was deleted in Joomla 4. Compatibility plugins do not restore it. Keep using PHP exceptions.
JError::raiseError() → throw new RuntimeException() / try-catch
What you will see
- Class "JError" not found
- Class "JException" not found
Symptoms people search
500 after save · error handling exploded on Joomla 4
Replace this code
Swap JError::raiseError() for throw new RuntimeException() / try-catch.
Joomla 3
Remove or stop calling this
JError::raiseError(500, 'Could not save');
$this->setError($db->getErrorMsg());Joomla 4 / 6
Use this instead
throw new \RuntimeException('Could not save');
// Catch at the controller and enqueue a messageHow to fix it
- 1Delete JError::raise* calls.
- 2Throw RuntimeException (or a domain exception) instead of setError().
- 3In controllers, catch and $app->enqueueMessage().
Also known as
JError · JException · raiseError · setError
There is no 1:1 swap for this one. The architecture changed. If you cannot rewrite it, Infyways can.
Related issues
- Joomla 3 → 4Joomla API
JRequest::getVar() and the whole JRequest API
JRequest::getVar() → $app->getInput()->get('id')
- Joomla 3 → 4Joomla API
isAdmin() / isSite()
$app->isAdmin() → $app->isClient('administrator') / isClient('site')
- Joomla 3 → 4Joomla API
Factory::getUri()
JFactory::getUri() → Uri::getInstance()
- Joomla 3 → 4Joomla API
Factory::getXml() / JXMLElement
JFactory::getXML() → SimpleXMLElement
- Joomla 3 → 4Joomla API
Factory::getEditor()
JFactory::getEditor() → Editor::getInstance()
- Joomla 3 → 4Joomla API
JHtmlBatch
JHtmlBatch → Layouts joomla.html.batch.*