'PHP modify trace of exception before throwing it

I'm on PHP 7.2 (no choice in the matter) and I have an error handler like this :

/**
 * @throws ErrorException
 */
function exception_error_handler($errno, $errstr, $errfile, $errline ) {
    throw new ErrorException($errstr, $errno, 0, $errfile, $errline);
}
set_error_handler("exception_error_handler");

It works well with detecting PHP errors, notices and warnings and converting them into exceptions, but for cleaner debugging purposes, I need to modify the stack trace before throwing the exception (so that the throw statement in exception_error_handler doesn't appear in said trace).

Is this even possible ? There doesn't seem to be a setTrace method for the exception..



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source