Handle errors in PHP code
It is possible to handle errors in PHP by placing code in try/catch block.
Try block will be used to execute piece of code, for example it can be division of one variable by another. If the divisor is equal to zero then it is an invalid operation and will produce a mathematical error.
There may be more then one catch block, each catch block will handle specific type of error. If error type is not specified then catch block will handle all of the error types.
In order to handle errors then code within catch block will be executed.
It is possible to specify one more section in try/catch block. It is denoted by keyword finally. It will be executed regardless if an error occurred or not. It maybe possible to omit catch block and only have finally block.
Comments
Post a Comment