Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

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
}

?>

Documentation

See Also