RE: [PHP-DEV] Concept: Lightweight error channels

From: Date: Sat, 26 Apr 2025 20:59:21 +0000
Subject: RE: [PHP-DEV] Concept: Lightweight error channels
References: 1  Groups: php.internals 
Request: Send a blank email to [email protected] to get a copy of this message
Hi,

Reading this as a PHP dev is confusing (terminology-wise) because errors
used to be the fatal ("stop the world") conditions while exceptions were the
catchable, recovarable issues within some call - feels to me pretty
equivalent to what you're proposing here.

What's the problem with PHP exceptions? I'm not even trying to argue, I'm
trying to understand. Is it the implementation (bad/expensive performance)?
Semantics? Handling syntax?

I didn't understand the bubbling changes either. What do you mean by
"fatal"? Does it turn the raised "light error" into a real exception? Or
does it turn into an actual error crashing the whole process?

    function div(int $n, int $d): float raises ZeroDivisor
    {
        if (!$d)
            raise new ZeroDivisor;
  
        return $n/$d;
    }

    function inverse(int $x): float
    {
        // does not handle the raise
        return div(1, $x);
    }

    // assuming the above functions are in a lib, can i rescue this using
some trycatch or not?
    inverse($_GET['x']);

And if I don't rescue, am I supposed to see that I passed a bad value to
inverse, a bad value to div or just that inverse failed to
handle a
raise?

BR,
Juris


Thread (34 messages)

« previous php.internals (#127190) next »