In my custom Joomla component, I got the below code

$db = Joomla\CMS\Factory::getDbo();
//some code
if (!$row->bind($this->_formdata)) {
    //do some code
  return false;
//some code

I understand that the method getErrorMsg is deprecated in Joomla 4. What is the best way to get the DB error inside the model store method.


1 Answer 1


I try to give just a short answer on this. We cannot say that there is an “equivalent” of your code snippet in Joomla 4 since Joomla has been handling errors with using core PHP Exceptions. And your code sample would get error in newer Joomla 3 also.

The old JError class were deprecated quite long time ago (at Joomla 3.1). The code editors shows this obviously at older error handlings in codes inside Joomla (at getError(), setError(), getErrorMsg() and so on…)

The bind() method - if it is the Table class method - is throwing an Exception \InvalidArgumentException, if the data (first parameter of the method: $src) is not an object or an array. Or if that method would be the Joomla Form class bind() method then it thrown an \UnexpectedValueException.

The important part to understand at this question is that we have to catch the \Exception thrown in the method (otherwise it will cause a PHP Fatal error of Uncaught exception…), so we have to use a try-catch block in this code and catch the Exception given in the method bind() which we are using in this part of the code.

catch (\InvalidArgumentException $e)
    // $e->getMessage(); // Exception message already set in the method we try to use...
    // do some code using the $e->getMessage(), but do not return it...
    // Factory::getApplication()->enqueueMessage($e->getMessage(), 'error'); // for example
    // or log it: Log::add($e->getMessage(), Log::WARNING, 'jerror');
    // or you can ignore the Exception
    return false;
  • Although the above is true for the bind() method, it is important to note that the transition to throwing exceptions rather than using setError() is still not complete, even with Joomla 5. The Table::store() method, for example, still catches exceptions from the database driver and uses setError(), as do several other methods.
    – John Rix
    May 9 at 13:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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