In Joomla 3.x and abov,e if any of your page has an SQL query which has a wrong syntax, then it will take you to an error page. In earlier versions it used to discard it and execute the next lines of code, but in the newer versions it just stops and throws the user to the error page.
This happens because of the following line written in the execute function of your database driver:
catch (RuntimeException $e)
// Get the error number and message.
$this->errorNum = $this->getErrorNumber();
$this->errorMsg = $this->getErrorMessage($query);
JLog::add(JText::sprintf('JLIB_DATABASE_QUERY_FAILED', $this->errorNum, $this->errorMsg), JLog::ERROR, 'database-error');
throw new RuntimeException($this->errorMsg, $this->errorNum, $e); //just comment out this line