Re: [PHP-DEV] exit() via exception

This is only part of a thread. view whole thread
  107528
October 13, 2019 10:09 thomas.lamy@netwake.de (Thomas Lamy)
Am 11.10.19 um 15:16 schrieb Claude Pache:
> >> Le 11 oct. 2019 à 13:05, Nikita Popov ppv@gmail.com> a écrit : >> >> I'm mainly wondering how exactly we'd go about integrating this in the >> existing exception hierarchy. Assuming that it is desirable to allow people >> to actually catch this exception, my first thought would be along these >> lines: >> >> Throwable (convert to abstract class) >> \-> Exception >> \-> Error >> \-> ExitThrowable >> >> This does mean though that existing code using catch(Throwable) is going to >> catch exit()s as well. This can be avoided by introducing *yet another* >> super-class/interface above Throwable, which is something I'd rather avoid. > > We should keep the semantics of `exit`, which is quite akin an early `return` in a function. Therefore: > > * Executing finally blocks (as does an early `return`) would be an improvement. > > * But intercepting it in a `catch` block or in an exception handler, is usually unwanted, contrarily to everything that currently implements `Throwable`. > > But if you do want to allow exit signals to be caught in catch blocks, there is no absolute necessity to introduce yet another superclass or superinterface, because you can write (since PHP 7.1): > > catch (\Throwable | \ExitSignal $e) > > —Claude
This! +1 Tom