copied from Symfony\Component\Debug\FlattenException::setTraceFromException - is there a place to share this code for non-exceptions?