type = \get_class($exception); $this->parent = $exception instanceof \Error ? self::PARENT_ERROR : self::PARENT_EXCEPTION; $this->message = $exception->getMessage(); $this->code = $exception->getCode(); $this->trace = Sync\flattenThrowableBacktrace($exception); if ($previous = $exception->getPrevious()) { $this->previous = new self($id, $previous); } } public function promise(): Promise { return new Failure($this->createException()); } private function createException(): TaskFailureThrowable { $previous = $this->previous ? $this->previous->createException() : null; if ($this->parent === self::PARENT_ERROR) { return new TaskFailureError($this->type, $this->message, $this->code, $this->trace, $previous); } return new TaskFailureException($this->type, $this->message, $this->code, $this->trace, $previous); } }