/** * Handle exception from scriptlet * * @param lang.Throwable t * @param int status * @param bool trace whether to show stacktrace * @return scriptlet.HttpScriptletResponse */ protected function fail(Throwable $t, $status, $trace) { $package = create(new XPClass(__CLASS__))->getPackage(); $errorPage = $package->providesResource('error' . $status . '.html') ? $package->getResource('error' . $status . '.html') : $package->getResource('error500.html'); $response = new HttpScriptletResponse(); $response->setStatus($status); $response->setContent(str_replace('<xp:value-of select="reason"/>', $trace ? $t->toString() : $t->getMessage(), $errorPage)); return $response; }
public function printStackTrace() { $out = new MemoryOutputStream(); $e = new Throwable('Test'); $e->printStackTrace(Streams::writeableFd($out)); $this->assertEquals($e->toString(), $out->getBytes()); }