+ // Get all call levels from backtrace
+ foreach ($exceptionInstance->getTrace() as $idx => $traceArray) {
+ // Init argument string
+ $argsString = '';
+
+ // Arguments given?
+ if (isset($traceArray['args'])) {
+ // Convert arguments type into human-readable
+ foreach ($traceArray['args'] as $arg) {
+ $argsString .= ', ' . gettype($arg);
+ }
+ $argsString = substr($argsString, 2);
+ }
+
+ // Set missing file/line
+ if (!isset($traceArray['file'])) $traceArray['file'] = 'unknown';
+ if (!isset($traceArray['line'])) $traceArray['line'] = '0';
+ if (!isset($traceArray['class'])) $traceArray['class'] = 'UnknownObject';
+ if (!isset($traceArray['type'])) $traceArray['type'] = '->';
+
+ $backTrace .= sprintf("---------- Pos %d: ----------
+Method : %s%s%s(%s)
+----- Caller: -----
+File : %s
+Line : %d\n",
+ ($idx + 1),
+ $traceArray['class'],
+ $traceArray['type'],
+ $traceArray['function'],
+ $argsString,
+ basename($traceArray['file']),
+ $traceArray['line']
+ );
+ }
+
+ // Construct the message
+ $message = sprintf("--------------------------------------------------------------------------------
+Uncaught Exception : %s
+--------------------------------------------------------------------------------
+Message : %s
+Code : %s
+File : %s
+Line : %d
+--------------------------------------------------------------------------------
+Backtrace:
+--------------------------------------------------------------------------------
+%s
+--------------------------------------------------------------------------------\n",
+ trim(html_entity_decode(strip_tags(get_class($exceptionInstance)))),
+ trim(html_entity_decode(strip_tags($exceptionInstance->getMessage()))),
+ ($exceptionInstance instanceof FrameworkException ? $exceptionInstance->getHexCode() : '0x' . bin2hex($exceptionInstance->getCode())),
+ $exceptionInstance->getFile(),
+ $exceptionInstance->getLine(),
+ trim($backTrace)
+ );
+
+ // Output the message
+ print($message);
+ } elseif (is_object($exceptionInstance)) {
+ // Output more details
+ printf('exceptionInstance=%s', print_r($exceptionInstance, true));
+ } else {
+ /*
+ * Invalid exception instance detected! Do *only* throw exceptions that
+ * extends our own exception 'FrameworkException' to get such nice
+ * outputs like above.
+ */
+ printf('exceptionInstance[]=%s is invalid! Please inform the core developer team.' . PHP_EOL, gettype($exceptionInstance));
+ }
+}