Does a PHP exception stop execution? Does a PHP exception stop execution? php php

Does a PHP exception stop execution?


Yes, uncaught exceptions result in fatal errors that stop the execution of the script. So the do_some_database_stuff function will not be called if an exception is thrown. You can read more about exceptions in this article.


Have a look at the PHP manual on exceptions.

When an exception is thrown, codefollowing the statement will not beexecuted, and PHP will attempt to findthe first matching catch block. If anexception is not caught, a PHP FatalError will be issued with an "UncaughtException ..." message, unless ahandler has been defined withset_exception_handler().

php.net/exceptions

So yes, the rest of the function is not being executed, a fatal error occurs instead.
If you catch the exception, execution of the script continues in the corresponding catch block, everything "between" the function which throws an exception and the catch block is not executed.


An exception, if not catched, will end script execution.

See the PHP manual chapter on Exceptions