On Mon, Jul 28, 2025 at 1:50 PM Rokas Šleinius <rave...@gmail.com> wrote:
> > On Mon, 28 Jul 2025 at 13:56, Tim Düsterhus <t...@bastelstu.be> wrote: > >> Hi >> >> Am 2025-07-28 11:41, schrieb Dmitry Derepko: >> > A few years ago I found that a library printed error traces wrong. >> > After a little research I found that there was a mix of 3rd party >> > integration error + raised error around the current bridge >> > implementation >> > (http client). >> > >> > There were several PHP applications with microservices architecture >> > which I >> > had access to (docker + sources). >> > >> > So having the message and traces I'd like to have an error chain as it >> > can >> > be done chaining several errors through a new Exception(previous: $e). >> > But PHP does not allow you to manually implement Throwable. Instead you >> > should extend Exception. But after that you still cannot override the >> > getTrace() method because it's final. >> > >> > So my proposal is pretty simple: Remove both restrictions. >> >> I'm afraid I don't quite understand what actual goal you intend to solve >> with the proposal. The description of your use case is very abstract, >> can you provide a real-world example of a use-case you want to enable? >> >> Best regards >> Tim Düsterhus >> > > | real-world example of a use-case you want to enable > > Say I am implementing a job runner, I do its error handling, and I want to > enrich the caught exception with additional helpful data for debugging. In > this process I create a custom exception MyJobHandlerException, but the > trace of the new exception includes my handler code, which the end user > does not care about. I wish to overwrite the trace of the new > MyJobHandlerException instance with the trace from the originally caught > exception, but I cannot. > > I was always sure that the reason behind all methods of \Exception being > final is Larry-Garfield-blogpost length/depth so I never bothered to ask > and made workarounds. > If I understand you correctly; You rethrow the exception, wrapping it in a custom exception class, and you'd like to have a final/composed stacktrace of all the exceptions? https://3v4l.org/m7HIQ#vnull