2017 © Pedro Peláez
 

library trycatch

Exception-handling callable wrapper

image

sanmai/trycatch

Exception-handling callable wrapper

  • Friday, November 3, 2017
  • by sanmai
  • Repository
  • 1 Watchers
  • 0 Stars
  • 29 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 5 Versions
  • 0 % Grown

The README.md

TryCatch

Latest Stable Version Build Status Coverage Status, (*1)

Exception-handling callable wrapper for Closures and other callables., (*2)

Usage

Suppose you were passing a closure to configure some dependencies, or do another mundane task:, (*3)

$object->setCallback($someCallback);

And then you suddenly find that your callback started throwing exceptions here and there. You have the callback from somewhere beyond your control, so you can't really change what it does., (*4)

Now, if you want to handle certain types of exceptions gracefully, this is how you could do that:, (*5)

$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

You can also peek into arguments, that were passed to the callback., (*6)

See tests for for additional examples., (*7)

Install

composer require sanmai/trycatch

The Versions

03/11 2017

dev-master

9999999-dev https://github.com/sanmai/trycatch

Exception-handling callable wrapper

  Sources   Download

MIT

The Requires

  • php ~5.6|~7.0

 

The Development Requires

php exception trycatch

03/11 2017

v0.2.1

0.2.1.0 https://github.com/sanmai/trycatch

Exception-handling callable wrapper

  Sources   Download

MIT

The Requires

  • php ~5.6|~7.0

 

The Development Requires

php exception trycatch

03/11 2017

dev-args

dev-args https://github.com/sanmai/trycatch

Exception-handling callable wrapper

  Sources   Download

MIT

The Requires

  • php ~5.6|~7.0

 

The Development Requires

php exception trycatch

14/06 2016

v0.2

0.2.0.0 https://github.com/sanmai/trycatch

Exception-handling callable wrapper

  Sources   Download

MIT

The Requires

  • php ~5.6|~7.0

 

The Development Requires

php exception trycatch

12/05 2016

v0.1

0.1.0.0 https://github.com/sanmai/trycatch

Exception-handling callable wrapper

  Sources   Download

MIT

The Requires

  • php ~5.6|~7.0

 

The Development Requires

php exception trycatch