Categories
BEST PHP CODE PHP PHPUnit

Useful catch (\Throwable $e)

catch (\Throwable $e) turned out to be very useful while coding in PHP.

When Exception were caught in specific instances, catch throwable would catch anything that would impede the code to run

Example below in a phpUnit scenario :

        try {
            $r = $this->checkKeys($data);
        } catch (\Throwable $e) {
            $this->assertEquals($e->getCode(), 404);
        }

Leave a Reply