Try/Catch block in PHP not catching Exception

There could be several reasons why a try/catch block in PHP is not catching an exception. Some common reasons include:

  1. The exception is not being thrown: Make sure that the code that you expect to throw the exception is actually doing so.

  2. The exception type is incorrect: Make sure that the exception being thrown is of the same type as the exception being caught.

  3. The exception is being thrown outside of the try block: The exception must be thrown within the try block in order for it to be caught by the catch block.

  4. The exception is being caught by a different catch block: Make sure that the exception is being caught by the correct catch block, and not by another catch block that may be present in the code.

  5. The exception is being caught but not handled properly: Make sure that you have implemented the necessary code to handle the exception within the catch block.

  6. The exception is rethrown: Make sure that the exception is not being rethrown in the catch block, which would cause the exception to be caught by another catch block or not caught at all.

Watch a course Learn object oriented PHP

It's important to check the error logs and debug the issue, you should check the exact error message to understand what the problem is.