Example #1
0
 /**
  * Render an exception as HTML string.
  *
  * @param Exception $e
  * @return string
  *   printable HTML text
  */
 public static function formatHtmlException(Exception $e)
 {
     $msg = '';
     // Exception metadata
     // Exception backtrace
     if ($e instanceof PEAR_Exception) {
         $ei = $e;
         while (is_callable(array($ei, 'getCause'))) {
             if ($ei->getCause() instanceof PEAR_Error) {
                 $msg .= '<table class="crm-db-error">';
                 $msg .= sprintf('<thead><tr><th>%s</th><th>%s</th></tr></thead>', ts('Error Field'), ts('Error Value'));
                 $msg .= '<tbody>';
                 foreach (array('Type', 'Code', 'Message', 'Mode', 'UserInfo', 'DebugInfo') as $f) {
                     $msg .= sprintf('<tr><td>%s</td><td>%s</td></tr>', $f, call_user_func(array($ei->getCause(), "get{$f}")));
                 }
                 $msg .= '</tbody></table>';
             }
             $ei = $ei->getCause();
         }
         $msg .= $e->toHtml();
     } else {
         $msg .= '<p><b>' . get_class($e) . ': "' . htmlentities($e->getMessage()) . '"</b></p>';
         $msg .= '<pre>' . htmlentities(self::formatBacktrace($e->getTrace())) . '</pre>';
     }
     return $msg;
 }