What makes the program flow into a catch
is the launch of a throw
. What are the throws
that exist in your application? Which ones are in the libraries you are using? Whether they belong to the PHP standard or additional. You have to read the documentation to know.
That is, it is the decision of the code developer. And this is probably in the documentation indicating whether you can or should use a catch
to capture the exception generated by some API you are using, even if it is not so clear.
PHP has some Apis that you can choose how the error will be generated. But this is not the default for all Apis and you probably won’t create this option in your code.
In PHP this is really confusing. But it will not be possible to list all the errors in one answer, there are many cases. As a general rule, when you use native PHP objects, it is a great chance for a method to produce an exception and not an error. And it is possible to set PHP to (almost) always generate exceptions instead of errors. I bet soon someone explains this in detail in a reply :)
– bfavaretto