src/precore/util/TryTo.php
public static function run(callable $tryBlock, array $exceptions = [], callable $finallyBlock = null) : TryTo
    {
        try {
            return Success::of(Functions::call($tryBlock));
        } catch (Exception $e) {
            if (count($exceptions) === 0) {
                return Failure::of($e);
            }
            $error = FluentIterable::of($exceptions)
                ->filter(Predicates::assignableFrom(get_class($e)))
                ->first();
            if ($error->isPresent()) {
                return Failure::of($e);
            }
            throw $e;
        } finally {
            if ($finallyBlock !== null) {
                Functions::call($finallyBlock);
            }
        }
    }
public static function run(callable $tryBlock, array $exceptions = [], callable $finallyBlock = null) : TryTo
    {
        try {
            return Success::of(Functions::call($tryBlock));
        } catch (Exception $e) {
            if (count($exceptions) === 0) {
                return Failure::of($e);
            }
            $error = FluentIterable::of($exceptions)
                ->filter(Predicates::assignableFrom(get_class($e)))
                ->first();
            if ($error->isPresent()) {
                return Failure::of($e);
            }
            throw $e;
        } finally {
            if ($finallyBlock !== null) {
                Functions::call($finallyBlock);
            }
        }
    }
Executes the given function within a try block, catches all exception types given and runs the finally block.

@param callable $tryBlock
@param Exception[] $exceptions should be caught, all exceptions will be handled if empty
@param callable $finallyBlock
@return TryTo
@throws Exception the thrown exception if it is not handled by this TryTo