Is it possible to catch exception and continue execution of script?
PHP allows a series of catch blocks following a try block to handle different exception cases. Various catch blocks may be employed to handle predefined exceptions and errors as well as user defined exceptions.
The “try… First, the code in try {...} is executed. If there were no errors, then catch (err) is ignored: the execution reaches the end of try and goes on, skipping catch . If an error occurs, then the try execution is stopped, and control flows to the beginning of catch (err) .
Catching all PHP exceptions Because exceptions are objects, they all extend a built-in Exception class (see Throwing Exceptions in PHP), which means that catching every PHP exception thrown is as simple as type-hinting the global exception object, which is indicated by adding a backslash in front: try { // ... }
Yes but it depends what you want to execute:
E.g.
try { a(); b(); } catch(Exception $e){ } c();
c()
will always be executed. But if a()
throws an exception, b()
is not executed.
Only put the stuff in to the try
block that is depended on each other. E.g. b
depends on some result of a
it makes no sense to put b
after the try-catch
block.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With