Skip to content

Commit

Permalink
Re-throw exception to invoke the native handler when a custom handler…
Browse files Browse the repository at this point in the history
… is not set
  • Loading branch information
BabakMN committed Feb 28, 2017
1 parent 3936d40 commit 77916b0
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 2 deletions.
8 changes: 6 additions & 2 deletions lib/Raven/ErrorHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,12 @@ public function handleException($e, $isError = false, $vars = null)
{
$e->event_id = $this->client->captureException($e, null, null, $vars);

if (!$isError && $this->call_existing_exception_handler && $this->old_exception_handler) {
call_user_func($this->old_exception_handler, $e);
if (!$isError && $this->call_existing_exception_handler) {
if ($this->old_exception_handler !== null) {
call_user_func($this->old_exception_handler, $e);
} else {
throw $e;
}
}
}

Expand Down
42 changes: 42 additions & 0 deletions test/Raven/Tests/ErrorHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,48 @@ public function testErrorHandlerPropagates()
$this->assertEquals($this->errorHandlerCalled, 1);
}

public function testExceptionHandlerPropagatesToNative()
{
$client = $this->getMockBuilder('Client')
->setMethods(array('captureException'))
->getMock();
$client->expects($this->exactly(2))
->method('captureException')
->with($this->isInstanceOf('Exception'));

$handler = new Raven_ErrorHandler($client);

set_exception_handler(null);
$handler->registerExceptionHandler(false);

$testException = new Exception('Test exception');

$didRethrow = false;
try {
$handler->handleException($testException);
} catch (Exception $e) {
$didRethrow = true;
}

$this->assertFalse($didRethrow);

set_exception_handler(null);
$handler->registerExceptionHandler(true);

$didRethrow = false;
$rethrownException = null;
try {
$handler->handleException($testException);
} catch (Exception $e) {
$didRethrow = true;
$rethrownException = $e;
}

$this->assertTrue($didRethrow);
$this->assertSame($testException, $rethrownException);

}

public function testErrorHandlerRespectsErrorReportingDefault()
{
$client = $this->getMockBuilder('Client')
Expand Down

0 comments on commit 77916b0

Please sign in to comment.