Invokes internal PHP function with own error handler.

@param callable $function
@param mixed[] $args
@param callable $onError function($message, $severity)
@return mixed
@throws \Throwable
166152
public static function invokeSafe(callable $function, array $args, callable $onError)
	{
		/** @noinspection PhpUnusedLocalVariableInspection */
		$prev = \set_error_handler(static function ($severity, $message, $file) use ($onError, & $prev) {
			if ($file === __FILE__ && $onError($message, $severity) !== false) {
				return null;
			}

			if ($prev) {
				return \call_user_func_array($prev, \func_get_args());
			}

			return false;
		});

		try {
			$res = \call_user_func_array($function, $args);
			\restore_error_handler();

			return $res;
		} catch (\Throwable $e) {
			\restore_error_handler();

			throw $e;
		}
	}
945758
protected function error(\Throwable $exception)
    {
        if ($this->errorHandler === null) {
            throw $exception;
        }

        ($this->errorHandler)($exception);
    }
295897
public static function error(callable $callback = null){
        $callback
          ? is_callable($callback) && static::$error = $callback
          : static::$error && call_user_func(static::$error);
    }
138940
private function triggerError($error, Http\Request $request, Http\Response $response)
    {
        if (! isset($this->options['onerror'])
            || ! is_callable($this->options['onerror'])
        ) {
            return;
        }

        $onError = $this->options['onerror'];
        $onError($error, $request, $response);
    }
239179
public static function deferArr(&$e, $callback, $args) {
		if (!is_callable($callback)) {
			if (is_string($callback) && !function_exists($callback)) {
				throw new \Exception("function '{$callback}' not exist");
			}
			throw new \Exception("this is not callable");
		}
		$e = new self($e, $callback, $args);
	}
1269511
public static function run(callable $function)
    {
        set_error_handler(static function($severity, $message, $file, $line) {
            throw new \ErrorException($message, 0, $severity, $file, $line);
        });

        try {
            $result = $function();
        } finally {
            restore_error_handler();
        }

        return $result;
    }
1118850
public static function allowExcessiveArguments(callable $function)
    {
        $reflection = Reflection::fromCallable($function);
        if ($reflection->isUserDefined()) {
            return $function;
        }

        if (Reflection::isVariadic($reflection)) {
            return $function;
        }

        $numberOfArguments = $reflection->getNumberOfParameters();

        $argumentLimiter = function () use ($function, $numberOfArguments) {
            return call_user_func_array($function, array_slice(func_get_args(), 0, $numberOfArguments));
        };

        /*
         * If there are default values, just use the default closure to
         * ensure correct default values are used for unsupplied arguments.
         */
        if ($numberOfArguments !== $reflection->getNumberOfRequiredParameters()) {
            return $argumentLimiter;
        }

        /*
         * Micro-optimization: provide simple wrappers for internal functions
         * with simple signatures rather than the more costly argument array slicing.
         */
        switch ($numberOfArguments) {
            case 0:
                return function () use ($function) {
                    return $function();
                };

            case 1:
                return function ($a) use ($function) {
                    return $function($a);
                };

            case 2:
                return function ($a, $b) use ($function) {
                    return $function($a, $b);
                };

            case 3:
                return function ($a, $b, $c) use ($function) {
                    return $function($a, $b, $c);
                };

            case 4:
                return function ($a, $b, $c, $d) use ($function) {
                    return $function($a, $b, $c, $d);
                };

            default:
                return $argumentLimiter;
        }
    }
485328
public function createRecoverableErrorAndCallHandler(
        IErrorHandler $handler,
        $number,
        $string,
        $file,
        $line
    ) {
        $error = new RecoverableError($number, $string, $file, $line);

        return $handler->handleRecoverableError($error);
    }
234312
public function convertErrorToExceptionAndCallHandler(
        IErrorHandler $handler,
        IError $error
    ) {
        return $handler->handleException(
            ErrorType::createExceptionForError($error)
        );

        return true;
    }
935895
protected function fail(\Throwable $error): void
    {
        if (~$this->state & AbstractPromise::PENDING) {
            return;
        }
        
        $callbacks = $this->result;
        
        $this->state ^= AbstractPromise::PENDING | AbstractPromise::FAILED;
        $this->result = $error;
        
        if ($this instanceof Cancellable) {
            $this->context->unregisterCancellation($this);
        }
        
        if ($callbacks) {
            if (\is_array($callbacks)) {
                foreach ($callbacks as $callback) {
                    try {
                        $callback($error);
                    } catch (\Throwable $e) {
                        $this->context->handleError($e);
                    }
                }
            } else {
                try {
                    $callbacks($error);
                } catch (\Throwable $e) {
                    $this->context->handleError($e);
                }
            }
        }
    }
839813
function onerror(cb) {
  return function (err) {
    if (err) {
      shas = {}
      arguments[0] = err instanceof Error ? err : new Error(err.toString())
    }
    cb.apply(null, arguments)
  }
}
277636
static function error2exception()
    {
        set_error_handler(
            function ($errno, $errstr, $errfile, $errline) {
                $r = error_reporting();
                if ($r & $errno) {
                    $exception = new \ErrorException($errstr, null, $errno,
                        $errfile, $errline);
                    if ($errno == E_USER_ERROR || $errno == E_RECOVERABLE_ERROR) {
                        throw $exception;
                    }
                    static::catchException($exception);
                }
            });
    }
1100209
function onFailure(/*callable*/$callable)
    {
        if ($callable === null) {
            $this->failure = $callable;
            return $this;
        }

        if (!is_callable($callable))
            throw new \Exception(sprintf(
                'The argument given is not callable; given: (%s).'
                , \Poirot\Std\flatten($callable)
            ));

        
        $this->failure = $callable;
        return $this;
    }
509840
protected function callErrorHandler($argument = null)
    {
        ob_start();
        if (is_callable($this->error)) {
            call_user_func_array($this->error, array($argument));
        } else {
            call_user_func_array(array($this, 'defaultError'), array($argument));
        }

        return ob_get_clean();
    }
407877
function call(channel, args, onError) {
        
        var result;
        var nextCalls = 0;
        var version = channel.split("@")[1] || "1.x";
        var channelName = normalizeChannelName(channel);
        var subscribers = prioritize(channelName in channels ? channels[channelName] : {}, version);
        
        var decorations = prioritize(
            merge(channelName in decorators ? decorators[channelName] : {}, decorators["*"] || {})
        );
        
        args = args || [];
        assert(Array.isArray(args), "Parameter `args` must be an array.");
        
        if (!subscribers.length) {
            throw new Error("No implementation connected for channel `" + channel + "`!");
        }
        
        subscribers.reverse().some(function (subscriber) {
            
            var newValue, lastValue, decorated;
            var decos = decorations.slice();
            
            decorated = decos.filter(versionMatches).map(function (decorator) {
                return {
                    fn: decorator.fn(next, {
                        method: "call",
                        channel: channel
                    }),
                    config: decorator.config
                };
            });
            
            decorated.push(subscriber);
            
            function versionMatches(decorator) {
                
                if (decorator.channel === "*") {
                    return true;
                }
                
                return semver.satisfies(subscriber.version, decorator.version);
            }
            
            function next() {
                
                var current, lastCallCount;
                var value = lastValue;
                
                nextCalls += 1;
                
                while (decorated.length) {
                    
                    current = decorated.shift();
                    
                    if (!decorated.length) {
                        
                        try {
                            value = current.fn.apply(null, arguments);
                        }
                        catch (error) {
                            error.mustReThrow = true;
                            throw error;
                        }
                        
                        break;
                    }
                    
                    try {
                        
                        lastCallCount = nextCalls;
                        value = current.fn.apply(null, arguments);
                        lastValue = value;
                        
                        if (nextCalls === lastCallCount) {
                            break;
                        }
                    }
                    catch (error) {
                        if (error && typeof error === "object" && error.mustReThrow) {
                            throw error;
                        }
                        else {
                            
                            if (current.config.onError) {
                                current.config.onError(error);
                            }
                            
                            bus.emit("decoratorError", current);
                        }
                    }
                    
                }
                
                return value;
            }
            
            try {
                
                newValue = next.apply(null, args);
                result = newValue;
                
                return true;
            }
            catch (error) {
                
                if (subscriber.config.onError) {
                    subscriber.config.onError(error);
                }
                
                if (onError) {
                    onError(error);
                }
                
                bus.emit("subscriberError", subscriber);
            }
            
            return false;
        });
        
        return result;
    }
398277
function (err, ctx, thisArg) {
    this.errorHanders.forEach(function (fn) {
      fn.call(thisArg, err, ctx);
    });

    return this;
  }
999418
private function createErrorHandler()
    {
        /*
         * @param int $severity
         * @param string $message
         * @param string $file
         * @param int $line
         * @return void
         * @throws ErrorException if error is not within the error_reporting mask.
         */
        return function (int $severity, string $message, string $file, int $line): void {
            if (error_reporting() & $severity) {
                throw new ErrorException($message, 0, $severity, $file, $line);
            }
        };
    }