Which errors trigger the catch?

Asked

Viewed 73 times

2

In a test similar to this, I was in doubt of what mistakes generate the Exception.

Researching I only found explanations of the use of try, catch, and some references that this would depend on the configuration of the php_ini.

Well, what mistakes do generate Exception?

  • 1

    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 :)

1 answer

2


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.

  • 1

    i fact I can choose to cast a throw, however what I want to say is about Exceptions standards.

  • 2

    This does not exist, today’s list is not the same as tomorrow. It would not make sense to list here. The function of the exception mechanism is precisely not to need to know all that exist. If this were important, the mechanism would be a much simpler one. You need to know what to use at that time and it varies according to a number of variable circumstances that you can’t put in an answer.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.