Page MenuHomePhabricator

In PHP7, "Throwable" and "Error" are exciting new exception classes
Closed, ResolvedPublic


PHP7 has introduced Throwable and Error. Among other things, this change means that Phabricator no longer prints out a lot of errors in development.

Throwable is a superclass, and Error and Exception subclass it.

Additionally, some error behaviors appear to have changed to "throw a Throwable" instead of whatever they used to do. On the balance, this is a good change, but it throws a bit of a wrench into the gears in the short term.

In practice, this means that code like this:

} catch (Exception $ex) {
} longer catches all exceptions.

In most cases, it is probably correct for us not to change things, but the top-level default exception handlers need to catch Throwable instead of (or in addition to) Exception. I think this construct should be safe in both PHP5 and PHP7:

} catch (Exception $ex) {
  // Do something.
} catch (Throwable $ex) {
  // Do the exact same thing.

We also typehint parameters as public function doThing(Exception $ex) in some cases. There is no meaningful typehint we can use here which will work in both PHP5 and PHP7 and allow us to pass either an Exception or a Throwable, so I think we just have to remove this typehinting (and replace it with comments or whatever, if there's a loss of clarity).

Event Timeline

epriestley added a revision: Restricted Differential Revision.Jun 19 2017, 8:05 PM

We removed the typehints elsewhere way back as well D14342 for compatability

epriestley claimed this task.

I think there will be a trickle of these for a while, but we seem to have found the most common cases.