diff --git a/www/_include.php b/www/_include.php
index cb202504c961ad0c6143455d83f2237c1ecd7404..927a8d79141c42cdb5783497345eefa0e9c5a695 100644
--- a/www/_include.php
+++ b/www/_include.php
@@ -27,8 +27,13 @@ SimpleSAML_Error_Assertion::installHandler();
 
 /* Show error page on unhandled exceptions. */
 function SimpleSAML_exception_handler(Exception $exception) {
-	$e = new SimpleSAML_Error_Error('UNHANDLEDEXCEPTION', $exception);
-	$e->show();
+
+	if ($exception instanceof SimpleSAML_Error_Error) {
+		$exception->show();
+	} else {
+		$e = new SimpleSAML_Error_Error('UNHANDLEDEXCEPTION', $exception);
+		$e->show();
+	}
 }
 set_exception_handler('SimpleSAML_exception_handler');