Try-catch
Try-catch is a PHP command, which runs a block of code, and catches some configured exceptions that the block may throw. It may be completed with a finally block.
The catch clause may be anonymous, when it only specifies the type of caught exception, without providing a variable name.
<?php
try {
callSomeMethod();
} catch (\Exception $e) {
// process the error here
}
?>
See Also
- PHP: Try and Catch me if you can!
- How to Implement Try Catch Finally Blocks in PHP
- A PHP Pattern To Avoid Try/Catch Blocks Repetition