Ok, I have made some changes more that I think improve the code.
On line 455 aprox.
Change
header("HTTP/1.1 301 Moved Permanently");
header('Location: ' . $tourl);
with
$app = JFactory::getApplication();
$tourl = str_replace('&','&',$tourl);
$app->redirect($tourl, $error->getMessage(), $msgType='message');
I think is better use the joomla way, and adding the informative message
On 535 (after the setErrorHandling)
restore_exception_handler();
I´m not sure about this one, but I think is the correct way to restore the handler
On line 543 and 551, where the get('level') are, I put this
$exception = new JException($error->getMessage(),
$error->getCode()
//, $error->get('level')
//, $error->get('info')
//, $error->get('backtrace')
);
// See what to do with this kind of error
//$handler = JError::getErrorHandling($exception->get('level'));
$handler = JError::getErrorHandling(E_ERROR);
I haven´t found the equivalent for get('level') and so
What do you think? If you think this ones are worth it, they could be integrate, in case is updated later.