PHP code example of sanmai / trycatch

1. Go to this page and download the library: Download sanmai/trycatch library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

sanmai / trycatch example snippets


$object->setCallback($someCallback);

$retval = $object->setCallback(\TryCatch\TryCatch::wrap($yourCallback)
  ->whenFailed(function (\Exception $e, $a, $b) {
    if ($e instanceof SpecificException) {
        // handle this one gracefully
        return null;             
    } elseif ($a > $b) {
        // else check for rogue callback's arguments
    }

    throw $e;
});
// $retval will be null in case of SpecificException being caught