/** * @internal * * Mango Framework uncaught exception handler * * Default Exception handler for mango. This gets called by the system * every time there is an uncaught exception thrown. * * @param Exception $exception The exception thrown * * @return void */ function mango_exception_handler($exception) { if (!MAppDelegate()->didRecoverFromUncaughtException($exception)) { logException($exception); if (!isRunningFromCommandLine() || isRunningInSimulatedRequestMode()) { $response = new MHTTPViewControllerResponse(new MErrorViewController(MHTTPResponse::RESPONSE_INTERNAL_SERVER_ERROR, N(MHTTPResponse::RESPONSE_INTERNAL_SERVER_ERROR), S("Internal Server Error"), S("Sorry but the page you are looking for could not be loaded due to an internal server error"))); $response->setCode(MHTTPResponse::RESPONSE_INTERNAL_SERVER_ERROR); MDie($response); } else { MDie(null, 1); } } }
/** * This function needs to be called after creating your instance of MApplication. * This is the entry point for your application's execution * * When you call this function, the Mango environment parses all the information * it needs, sets itself up and boots up its classes * * This is also where routing occours. The system finds the controller class for * the specified URL and loads it * * The system takes care of handling top-level errors that may occur. For example, * if the URL requested by the user has no registered controllers, the system returns * a 404 View to the user and responds with the appropriate HTTP code. * * The same thing happens if an exception is thrown and not caught or if another error * occurs in the execution of your code. The system catches the error, outputs the * appropriate error information to the error log and returns an 500 Internal Server * Error view to the client * * @return void */ public function run() { $response = null; $returnCode = 0; if ($this->isRunningFromCommandLine()) { $returnCode = $this->delegate()->didFinishLaunchingFromCommandLineWithArguments($this->commandLineArguments()); } else { $viewController = null; try { $this->delegate()->didFinishLaunching(); $viewController = $this->rootViewController(); } catch (MBadRequestException $e) { logException($e); $viewController = MObject::newInstanceOfClassWithParameters($this->errorViewControllerClass(), A(MHTTPResponse::RESPONSE_BAD_REQUEST, N(MHTTPResponse::RESPONSE_BAD_REQUEST), S("Bad Request"), $e->description())); } catch (MException $e) { logException($e); $viewController = MObject::newInstanceOfClassWithParameters($this->errorViewControllerClass(), A(MHTTPResponse::RESPONSE_INTERNAL_SERVER_ERROR, N(MHTTPResponse::RESPONSE_INTERNAL_SERVER_ERROR), S("Internal Server Error"), S("Sorry but the page you are looking for could not be loaded due to an internal server error"))); } if (!$viewController) { $viewController = MObject::newInstanceOfClassWithParameters($this->errorViewControllerClass(), A(MHTTPResponse::RESPONSE_NOT_FOUND, N(MHTTPResponse::RESPONSE_NOT_FOUND), S("Not Found"), S("Sorry but the page you are looking for could not be found"))); } $response = new MHTTPViewControllerResponse($viewController); } MDie($response, $returnCode); }