/**
  * execute exception handlers
  *
  * @param Exception $e     exception to handle
  *
  * @return boolean        TRUE means the exception is handled, otherwise FALSE
  */
 public function handleException($e)
 {
     Charcoal_ParamTrait::validateException(1, $e);
     if ($e instanceof Charcoal_ProcessEventAtTaskManagerException) {
         $e = $e->getPrevious();
         if ($e instanceof Charcoal_CreateObjectException) {
             $path = $e->getObjectPath();
             echo "illegal object path: {$path}" . PHP_EOL;
             return true;
         } else {
             if ($e instanceof Charcoal_ObjectPathFormatException) {
                 $path = $e->getObjectPath();
                 echo "bad object path: {$path}" . PHP_EOL;
                 return true;
             } else {
                 if ($e instanceof Charcoal_ModuleLoaderException) {
                     $path = $e->getModulePath();
                     echo "failed to load module: {$path}" . PHP_EOL;
                     return true;
                 } else {
                     if ($e instanceof Charcoal_InvalidShellArgumentException) {
                         $option_name = $e->getOptionName();
                         $argument = $e->getArgument();
                         echo "invalid option[{$option_name}]: {$argument}" . PHP_EOL;
                         return true;
                     }
                 }
             }
         }
     }
     return false;
 }
 /**
  *    Construct
  */
 public function __construct($message, $prev = NULL)
 {
     Charcoal_ParamTrait::validateString(1, $message);
     Charcoal_ParamTrait::validateException(2, $prev, TRUE);
     parent::__construct(us($message), 0, $prev);
     $this->backtrace = debug_backtrace();
     $this->previous = $prev;
 }
 public function __construct($component_name, $entry, $message = NULL, $prev = NULL)
 {
     Charcoal_ParamTrait::validateString(1, $component_name);
     Charcoal_ParamTrait::validateString(2, $entry);
     Charcoal_ParamTrait::validateString(3, $message);
     Charcoal_ParamTrait::validateException(4, $prev, TRUE);
     parent::__construct("component({$component_name}) config maybe wrong: [entry]{$entry} [message]{$message}", $prev);
 }
 public function __construct($argument, $option_name, $prev = NULL)
 {
     Charcoal_ParamTrait::validateString(1, $argument);
     Charcoal_ParamTrait::validateString(2, $option_name);
     Charcoal_ParamTrait::validateException(3, $prev, TRUE);
     $this->argument = $argument;
     $this->option_name = $option_name;
     parent::__construct("Invalid argument for -{$option_name}: {$argument}", $prev);
 }
 /**
  * Output HTML
  *
  */
 public function output($e)
 {
     Charcoal_ParamTrait::validateException(1, $e);
     $out = '';
     $version = Charcoal_Framework::getVersion();
     $out .= "=============================================================" . PHP_EOL;
     $out .= "CharcoalPHP Ver.{$version}: Exception stack trace " . PHP_EOL;
     $out .= "=============================================================" . PHP_EOL;
     $out .= PHP_EOL;
     $out .= "* Exception Stack *" . PHP_EOL;
     $out .= "-------------------------------------------------------------" . PHP_EOL;
     $first_exception = $e;
     $no = 1;
     while ($e) {
         // get exception info
         $clazz = get_class($e);
         $file = $e->getFile();
         $line = $e->getLine();
         $message = $e->getMessage();
         // print exception info
         $out .= "[{$no}]{$clazz}" . PHP_EOL;
         $out .= "   {$file}({$line})" . PHP_EOL;
         $out .= "   {$message}" . PHP_EOL;
         // move to previous exception
         $e = method_exists($e, 'getPreviousException') ? $e->getPreviousException() : NULL;
         $no++;
         if ($e) {
             $out .= PHP_EOL;
         }
     }
     // get backtrace
     if ($first_exception instanceof Charcoal_CharcoalException) {
         $backtrace = $first_exception->getBackTrace();
         $out .= PHP_EOL;
         $out .= "* Call Stack *" . PHP_EOL;
         $out .= "-------------------------------------------------------------" . PHP_EOL;
         // print backtrace
         $call_no = 0;
         foreach ($backtrace as $element) {
             $klass = isset($element['class']) ? $element['class'] : '';
             $func = isset($element['function']) ? $element['function'] : '';
             $type = isset($element['type']) ? $element['type'] : '';
             $file = isset($element['file']) ? $element['file'] : '';
             $line = isset($element['line']) ? $element['line'] : '';
             if ($call_no > 0) {
                 $out .= PHP_EOL;
             }
             $out .= "[{$call_no}]{$klass}{$type}{$func}()" . PHP_EOL;
             $out .= "   {$file}({$line})" . PHP_EOL;
             $call_no++;
         }
     }
     return $out;
 }
 /**
  * execute exception handlers
  *
  * @param Exception $e     exception to handle
  *
  * @return boolean        TRUE means the exception is handled, otherwise FALSE
  */
 public function handleException($e)
 {
     Charcoal_ParamTrait::validateException(1, $e);
     if ($e instanceof Charcoal_HttpStatusException) {
         $status_code = $e->getStatusCode();
         // Show HTTP error document
         self::showHttpErrorDocument($status_code);
         log_warning('system,error', 'exception', "http_exception: status_code={$status_code}");
         return TRUE;
     }
     return FALSE;
 }
 /**
  * execute exception handlers
  *
  * @param Exception $e     exception to handle
  *
  * @return boolean        TRUE means the exception is handled, otherwise FALSE
  */
 public function handleException($e)
 {
     Charcoal_ParamTrait::validateException(1, $e);
     log_info("system, debug", "exception", "handled a framework exception!");
     try {
         /** @var Charcoal_IDebugtraceRenderer $renderer */
         $renderer = $this->getSandbox()->createObject('console', 'debugtrace_renderer', array(), 'Charcoal_IDebugtraceRenderer');
         // Render exception
         $renderer->render($e);
         return TRUE;
     } catch (Exception $e) {
         _catch($e);
         log_info("system, debug", "exception", "debugtrace_renderer creation failed.");
     }
     return FALSE;
 }
 /**
  * execute exception handlers
  *
  * @param Exception $e     exception to handle
  *
  * @return boolean        TRUE means the exception is handled, otherwise FALSE
  */
 public function handleException($e)
 {
     Charcoal_ParamTrait::validateException(1, $e);
     log_info('system, debug', "handled a framework exception!", 'exception_handler');
     // Create Debug Trace Renderer
     try {
         $debugtrace_renderer = $this->getSandbox()->createObject('html', 'debugtrace_renderer', array(), 'Charcoal_IDebugtraceRenderer');
         log_info('system, debug', "debugtrace_renderer[{$debugtrace_renderer}] created.", 'exception_handler');
         // Render exception
         $error_html = $debugtrace_renderer->output($e);
         log_info('system, debug', "debugtrace_renderer[{$debugtrace_renderer}] output html.", 'exception_handler');
         // generate error dump(HTML)
         log_error('error_dump', $error_html, 'exception_handler');
         log_info('system, debug', "error_html:\n{$error_html}", 'exception_handler');
         return TRUE;
     } catch (Exception $e) {
         _catch($e);
         log_info('system, debug', "debugtrace_renderer[{$debugtrace_renderer}] creation failed.", 'exception_handler');
     }
     return FALSE;
 }
 /**
  * execute exception handlers
  *
  * @param Exception $e     exception to handle
  *
  * @return boolean        TRUE means the exception is handled, otherwise FALSE
  */
 public function handleException($e)
 {
     Charcoal_ParamTrait::validateException(1, $e);
     if ($e instanceof Charcoal_HttpStatusException) {
         $status_code = $e->getStatusCode();
         // ヘッダ文字列
         $status_message_file = Charcoal_ResourceLocator::getFrameworkPath('preset', 'status_messages.ini');
         if (!is_file($status_message_file)) {
             //            log_warning( 'system,debug,error', 'framework',"ステータスメッセージファイル($status_message_file)が存在しません。");
         }
         $status_messages = parse_ini_file($status_message_file, FALSE);
         if (FALSE === $status_messages) {
             //            log_warning( 'system,debug,error', 'framework',"ステータスメッセージファイル($status_message_file)の読み込みに失敗しました。");
         }
         $header_msg = isset($status_messages[$status_code]) ? $status_messages[$status_code] : '';
         // HTTPバージョン文字列
         $http_ver = $this->http_version;
         // ヘッダ出力
         header("HTTP/{$http_ver} {$status_code} {$header_msg}", true, $status_code);
         log_error('system,debug,error', "HTTP/1.0 {$status_code} {$header_msg}", 'framework');
     }
     return FALSE;
 }
 /**
  * Render debug trace
  *
  */
 public function render($e)
 {
     Charcoal_ParamTrait::validateException(1, $e);
     fputs(STDERR, $this->output($e));
     return TRUE;
 }
 /**
  * Output HTML
  *
  */
 public function output($e)
 {
     Charcoal_ParamTrait::validateException(1, $e);
     $out = '';
     $version = Charcoal_Framework::getVersion();
     $out .= "=============================================================" . self::LOG_EOL;
     $out .= "CharcoalPHP Ver.{$version}: Exception stack trace " . self::LOG_EOL;
     $out .= "=============================================================" . self::LOG_EOL;
     $out .= self::LOG_EOL;
     $out .= "* Exception Stack *" . self::LOG_EOL;
     $out .= "-------------------------------------------------------------" . self::LOG_EOL;
     $no = 1;
     while ($e) {
         // get exception info
         $clazz = get_class($e);
         $file = $e->getFile();
         $line = $e->getLine();
         $message = $e->getMessage();
         $backtrace = $e instanceof Charcoal_CharcoalException ? $e->getBackTrace() : NULL;
         // print exception info
         $out .= "[{$no}]{$clazz}" . self::LOG_EOL;
         $out .= "   {$file}({$line})" . self::LOG_EOL;
         $out .= "   {$message}" . self::LOG_EOL;
         // move to previous exception
         $e = method_exists($e, 'getPreviousException') ? $e->getPreviousException() : NULL;
         $no++;
         if ($e) {
             $out .= self::LOG_EOL;
         }
     }
     if ($backtrace === NULL || !is_array($backtrace)) {
         return $out;
     }
     $out .= self::LOG_EOL;
     $out .= "* Call Stack *" . self::LOG_EOL;
     $out .= "-------------------------------------------------------------" . self::LOG_EOL;
     // print backtrace
     $call_no = 0;
     foreach ($backtrace as $element) {
         $klass = isset($element['class']) ? $element['class'] : '';
         $func = isset($element['function']) ? $element['function'] : '';
         $type = isset($element['type']) ? $element['type'] : '';
         $args = isset($element['args']) ? $element['args'] : array();
         $file = isset($element['file']) ? $element['file'] : '';
         $line = isset($element['line']) ? $element['line'] : '';
         $args_disp = '';
         foreach ($args as $arg) {
             if (strlen($args_disp) > 0) {
                 $args_disp .= ',';
             }
             $args_disp .= Charcoal_System::toString($arg);
         }
         if ($call_no > 0) {
             $out .= self::LOG_EOL;
         }
         $out .= "[{$call_no}]{$klass}{$type}{$func}({$args_disp})" . self::LOG_EOL;
         $out .= "   {$file}({$line})" . self::LOG_EOL;
         $call_no++;
     }
     return $out;
 }
 /**
  * Output HTML
  *
  */
 public function output($e)
 {
     Charcoal_ParamTrait::validateException(1, $e);
     list($file, $line) = Charcoal_System::caller(0);
     $title = 'CharcoalPHP: Exception List';
     return $this->_output($e, $title, $file, $line);
 }