Assert exception was thrown without stopping a test

1.1.0 2020-10-02 11:37 UTC

This package is auto-updated.

Last update: 2021-01-18 19:36:59 UTC


Handle exceptions inside a test without a stop! Works with PHPUnit and Codeception.

Build Status


composer require codeception/assert-throws --dev

Include AssertThrows trait it to a TestCase:


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



Catch exception thrown inside a code block.


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

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

// you can also assert that an exception is not throw
$this->assertDoesNotThrow(NotFoundException::class, function() {

You can optionally test the exception message:


    NotFoundException::class, 'my error message', function() {
	throw new NotFoundException('my error message');

License MIT