function runApp(LiveCart $app) { static $attempts = 0; // check if we're not getting into an endless loop if (++$attempts > 5) { try { $app->run(); } catch (Exception $e) { dump_livecart_trace($e); die('error'); } } try { if ($app->isDevMode()) { try { $app->run(); } catch (Exception $e) { if (!$e instanceof HTTPStatusException) { dump_livecart_trace($e); } else { throw $e; } } } else { $app->run(); } } catch (HTTPStatusException $e) { if ($e->getController() instanceof BackendController) { $route = 'backend.err/redirect/' . $e->getStatusCode(); } else { $route = 'err/redirect/' . $e->getStatusCode(); } $app->getRouter()->setRequestedRoute($route); runApp($app); } catch (ARNotFoundException $e) { $app->getRouter()->setRequestedRoute('err/redirect/404'); runApp($app); } catch (ControllerNotFoundException $e) { $app->getRouter()->setRequestedRoute('err/redirect/404'); runApp($app); } catch (ActionNotFoundException $e) { $app->getRouter()->setRequestedRoute('err/redirect/404'); runApp($app); } catch (UnsupportedBrowserException $e) { header('Location: ' . $app->getRouter()->createUrl(array('controller' => 'err', 'action' => 'backendBrowser'))); exit; } catch (SQLException $e) { $_REQUEST['exception'] = $e; $app->getRouter()->setRequestedRoute('err/database'); runApp($app); } catch (Exception $e) { $route = 'err/redirect/500'; $app->getRouter()->setRequestedRoute($route); runApp($app); } }