Assert exception was thrown without stopping a test

1.0.2 2019-08-15 13:29 UTC

This package is auto-updated.

Last update: 2020-06-15 15:26:08 UTC


Build Status

Handle exceptions inside a test without a stop!

Assertions for exceptions. Works with PHPUnit and Codeception.


Catch exception thrown inside a code block.

$this->assertThrows(NotFoundException::class, function() {

// alternatively
$this->assertThrows(new NotFoundException, function() {

You can optionally test the exception message:

$this->assertThrowsWithMessage(NotFoundException::class, 'my error message', function() {
	throw new NotFoundException('my error message');


composer require codeception/assert-throws --dev

Include AssertThrows trait it to a TestCase:

class MyTest extends PHPUnit\Framework\TestCase
    use Codeception\AssertThrows;


License MIT