Back to CMSObject class

Method getError

public string
getError
(mixed $i = null, mixed $toString = true)
Get the most recent error message.
Parameters
  • int $i Option error index.
  • bool $toString Indicates if Exception objects should return their error message.
Returns
  • string Error message
Since
  • 1.7.0
Deprecated
  • 3.1.4
Class: CMSObject
Project: Joomla

Method getError - Source code

/**
 * Get the most recent error message.
 *
 * @param   integer  $i         Option error index.
 * @param   boolean  $toString  Indicates if Exception objects should return their error message.
 *
 * @return  string   Error message
 *
 * @since   1.7.0
 * @deprecated 3.1.4  JError has been deprecated
 */
public function getError($i = null, $toString = true)
{
    // Find the error
    if ($i === null) {
        // Default, return the last message
        $error = end($this->_errors);
    } elseif (!\array_key_exists($i, $this->_errors)) {
        // If $i has been specified but does not exist, return false
        return false;
    } else {
        $error = $this->_errors[$i];
    }
    // Check if only the string is requested
    if ($error instanceof \Exception && $toString) {
        return $error->getMessage();
    }
    return $error;
}