Hi PHP
So I read that there's this Throwable interface coming. Great! How about
extending it with one further method:
void Throwable::addSuppressed(Throwable exception)
Semantic is the same as Java's Throwable.addSuppressed()¹.
Why? Well consider a code fragment which wants to close a resource
during an exception:
} catch (Exception $e1) {
try {
$resource->close();
throw $e1;
} catch (ResourceException $e2) {
// The information about $e2 is lost.
throw $e1;
}
}
Currently PHP has no method to propagate both $e1 and $e2. With
Throwable::addSuppressed() $e2 could be added as a suppressed exception
to $e1:
} catch (Exception $e1) {
try {
$resource->close();
} catch (ResourceException $e2) {
e1->addSuppressed($e2);
}
throw $e1;
}
To make this information useful (for e.g. a logger) there's one further
method needed:
Throwable[] Throwable::getSuppressed()
So PHP, what do you think, might a RFC find acceptance?
Best wishes
Markus Malkusch
Hi PHP
So I read that there's this Throwable interface coming. Great! How about
extending it with:void Throwable::addSuppressed(Throwable exception)
Throwable[] Throwable::getSuppressed()
So PHP, what do you think, might a RFC find acceptance?
Yes.
Are you going to write an RFC for it? If not, do you mind if I start
writing the RFC with you either listed as co-author or 'the ideas guy'
?
cheers
Dan
Dan Ackroyd:
Are you going to write an RFC for it?
I'm going to do that. But if there's any time pressure feel free to take
it over.
Regards
Markus