I have had a very hard time with this query and it was suggested to me to learn try and catch blocks to more easily figure out what is wrong. So this is my first attempt at it.<
If you wanna track all the errors that happen in your code, you can use try, catch statements to handle them in proper way. Inside try block, you can put all your code or part of it. If something fails, it will generate an exception.
That exception also can be thrown by yourself using the next statement:
throw new Exception("I think something's failing");
Just after try block, you have to declare the catch block which will handle the exception, making it available to you. In the following example I will print the error message.
<?php
try {
/* all your code */
} catch (Exception $e) {
/* if something fails inside try block will be catched here */
print $e->getMessage();
}
You can find more about this here: http://php.net/manual/en/language.exceptions.php