public static function tryFopen(string $filename, string $mode)
    {
        $ex = null;

        \set_error_handler(static function () use ($filename, $mode, &$ex): void {
            $ex = new RuntimeException(\sprintf(
                'Unable to open [%s] using mode %s: %s',
                $filename,
                $mode,
                \func_get_args()[1]
            ));
        });

        $handle = \fopen($filename, $mode);

        \restore_error_handler();

        if ($ex instanceof Throwable) {
            // @var $ex \RuntimeException
            throw $ex;
        }

        return $handle;
    }