Skip to content

Commit

Permalink
Application::processException(), $onError and $onShutdown handles Thr…
Browse files Browse the repository at this point in the history
…owable errors (BC break)
  • Loading branch information
dg committed Nov 25, 2015
1 parent 31ae841 commit 8d1573a
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/Application/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class Application extends Nette\Object
/** @var callable[] function (Application $sender); Occurs before the application loads presenter */
public $onStartup;

/** @var callable[] function (Application $sender, \Exception $e = NULL); Occurs before the application shuts down */
/** @var callable[] function (Application $sender, \Exception|\Throwable $e = NULL); Occurs before the application shuts down */

This comment has been minimized.

Copy link
@JanTvrdik

JanTvrdik Dec 3, 2015

Contributor

isn't \Throwable enough for phpDoc?

public $onShutdown;

/** @var callable[] function (Application $sender, Request $request); Occurs when a new request is received */
Expand All @@ -39,7 +39,7 @@ class Application extends Nette\Object
/** @var callable[] function (Application $sender, IResponse $response); Occurs when a new response is ready for dispatch */
public $onResponse;

/** @var callable[] function (Application $sender, \Exception $e); Occurs when an unhandled exception occurs in the application */
/** @var callable[] function (Application $sender, \Exception|\Throwable $e); Occurs when an unhandled exception occurs in the application */
public $onError;

/** @var Request[] */
Expand Down Expand Up @@ -81,14 +81,19 @@ public function run()
$this->processRequest($this->createInitialRequest());
$this->onShutdown($this);

} catch (\Throwable $e) {
} catch (\Exception $e) {
}
if (isset($e)) {
$this->onError($this, $e);
if ($this->catchExceptions && $this->errorPresenter) {
try {
$this->processException($e);
$this->onShutdown($this, $e);
return;

} catch (\Throwable $e) {
$this->onError($this, $e);
} catch (\Exception $e) {
$this->onError($this, $e);
}
Expand Down Expand Up @@ -153,9 +158,10 @@ public function processRequest(Request $request)


/**
* @param \Exception|\Throwable
* @return void
*/
public function processException(\Exception $e)
public function processException($e)
{
if (!$e instanceof BadRequestException && $this->httpResponse instanceof Nette\Http\Response) {
$this->httpResponse->warnOnBuffer = FALSE;
Expand Down

0 comments on commit 8d1573a

Please sign in to comment.