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;
		}
	}