php thorwable vs exception

Solutions on MaxInterview for php thorwable vs exception by the best coders in the world

showing results for - "php thorwable vs exception"
Jesús
04 Jul 2018
1
2Throwable does not work on PHP 5.x.
3
4To catch both exceptions and errors in PHP 5.x and 7, add a catch block for Exception AFTER catching Throwable first.
5Once PHP 5.x support is no longer needed, the block catching Exception can be removed.
6
7try
8{
9   // Code that may throw an Exception or Error.
10}
11catch (Throwable $t)
12{
13   // Executed only in PHP 7, will not match in PHP 5
14}
15catch (Exception $e)
16{
17   // Executed only in PHP 5, will not be reached in PHP 7
18}
19