Re: RFC: Expectations

From: Date: Tue, 22 Oct 2013 18:41:55 +0000
Subject: Re: RFC: Expectations
References: 1 2 3 4 5 6 7 8 9  Groups: php.internals 
Request: Send a blank email to [email protected] to get a copy of this message
On Tue, Oct 22, 2013 at 8:32 PM, Patrick Schaaf <[email protected]> wrote:

> Am 22.10.2013 20:07 schrieb "Joe Watkins" <[email protected]>:
> >
> > You can catch exceptions, and log them.
> > You can do that without impacting everything around you, you can do that,
> or whatever else you like.
>
> You can do that handling when you have only a few toplevel scripts, like
> when you have a setup with a small number of toplevel controllers and
> almost no CLI stuff around. But due to the scoped nature of try/catch you
> cannot reasonably / painlessly do that when you have 270 toplevel web and
> CLI entry points that then each need such a try/catch block.
>
> Also, there is the problem with catch (Exception) blocks, which you might
> easily dismiss as bad form, but which I'm sure are widespread in the field
> - I certainly know they are in our codebase...
>
> On the other hand, setup of an assertion-failed callback can easily go into
> an auto_prepend file, or into any other standard include (autoloader or
> something) you might have - exactly because it is something done on the
> global level instead of the scoped try/catch requirement.
>

If you want to handle uncaught exceptions via auto_prepend_file you can use
set_exception_handler(). It will register a global handler that is invoked
on an uncaught exception. So you can have your functionality, if that's how
you like to handle things, but you also have the option of fine-grained
control of assertion failures by use of catch-blocks. One use case that I
have repeatedly mentioned in the previous thread is that PHPUnit will want
to catch the assertion failure but still continue running other tests.

Generally anything that uses a global handler (e.g. for assertion
failures...) turns out to be a PITA when you try to combine multiple
libraries which want different handlers. In the end you can't really use
any such handlers in a portable library. I'd like assertions to be usable
in libraries.

Thanks,
Nikita


Thread (51 messages)

« previous php.internals (#69776) next »