Exemplo n.º 1
0
 /**
  * Static s_display_error
  */
 static function generic_display_error(exception $ex)
 {
     $title = $ex->getMessage();
     $err_no = $ex->getCode();
     if (!class_exists('loader') || class_exists('loader') && !loader::in_ajax()) {
         header('', true, 500);
         $message = '<style>* {font: 0.97em verdana;} a {text-decoration:none;background:#EFEFEF;padding:4px;} a:hover{background: red;}</style><h1>Ups! We have an error here.</h1>';
         $subject = "Error " . " at " . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
         $message .= 'Visit <a href="/">index</a> page.<br/><br/>';
         echo $message;
         // if debug
         if (class_exists('core') && core::is_debug()) {
             echo '<br/>Error : ' . $title . ' : ' . $err_no;
             echo '<br/><br/>' . nl2br($ex->getTraceAsString());
         }
     }
 }
Exemplo n.º 2
0
Arquivo: Error.php Projeto: xn1224/YOF
 /** 
  * Show YAF Error 
  * only display errors under DEV, else save error in LOG_FILE
  * @param exception $exception
  * @return void
  */
 public function errorAction($exception)
 {
     switch ($exception->getCode()) {
         case YAF_ERR_NOTFOUND_MODULE:
         case YAF_ERR_NOTFOUND_CONTROLLER:
         case YAF_ERR_NOTFOUND_ACTION:
         case YAF_ERR_NOTFOUND_VIEW:
             if (ENV == 'DEV') {
                 echo 404, ":", $exception->getMessage();
             } else {
                 echo 404;
                 file_put_contents(LOG_FILE, $exception->getMessage() . PHP_EOL, FILE_APPEND);
             }
             break;
         default:
             if (ENV == 'DEV') {
                 echo 0, ":", $exception->getMessage();
             } else {
                 echo 'Unknown error';
                 file_put_contents(LOG_FILE, $exception->getMessage() . PHP_EOL, FILE_APPEND);
             }
             break;
     }
 }
 /**
  * Handles all PHP exceptions.
  *
  * @param exception|\exception $exception An exception.
  *
  * @note Exceptions handled successfully by this routine will NOT be logged by PHP as errors.
  *    As the exception handler, we will need to log and/or display anything that needs to be recorded here.
  *    The PHP interpreter simply terminates script execution whenever an exception occurs (nothing more).
  *
  * @note If an exception is thrown while handling an exception; PHP will revert to it's default exception handler.
  *    This will result in a fatal error that may get logged by PHP itself (depending on `error_reporting` and `error_log`).
  *
  * @throws exception|\exception If we are unable to handle the exception (i.e. the XDaRk Core is not even available yet),
  *    this handler will simply re-throw the exception (forcing a fatal error); as just described in the previous note.
  *
  * @note The display of exception messages is NOT dependent upon `display_errors`; nor do we consider that setting here.
  *    However, we do tighten security within the `exception.php` template file; hiding most details by default; and displaying all details
  *    only if the current user is a Super Administrator in WordPress; or if `WP_DEBUG_DISPLAY` mode has been enabled on this site.
  *
  * @note If there was another exception handler active on the site; and this exception is NOT for
  *    a plugin under this version of the XDaRk Core; we simply hand the exception back to the previous handler.
  *    In the case of multiple versions of the XDaRk Core across various plugins; this allows us to work up the chain
  *    of previous handlers until we find the right version of the XDaRk Core; assuming each version
  *    of the XDaRk Core handles things this way too (which is to be expected).
  *
  * @see http://php.net/manual/en/function.set-exception-handler.php
  */
 public static function handle(\exception $exception)
 {
     try {
         static::$exception = $exception;
         // Reference.
         if (static::$exception instanceof exception) {
             static::$plugin = static::$exception->plugin;
             static::handle_plugin_exception();
             return;
             // We're done here.
         }
         // Else this is some other type of exception.
         if (static::$previous_handler && is_callable(static::$previous_handler)) {
             call_user_func(static::$previous_handler, static::$exception);
             return;
             // We're done here.
         }
         // There is NO other handler available (deal w/ it here; if possible).
         if (is_callable('\\' . stub::$core_ns . '\\core')) {
             static::$plugin = core();
             static::handle_plugin_exception();
             return;
             // We're done here.
         }
         throw static::$exception;
         // Re-throw (forcing a fatal error).
     } catch (\exception $_exception) {
         throw new \exception(sprintf(stub::__('Failed to handle exception code: `%1$s` with message: `%2$s`.'), $exception->getCode(), $exception->getMessage()) . ' ' . sprintf(stub::__('Failure caused by exception code: `%1$s` with message: `%2$s`.'), $_exception->getCode(), $_exception->getMessage()), 20, $_exception);
     }
 }
 /**
  * handling the error to catch fatal errors.
  *
  * @param int              $errno   error number
  * @param string|exception $errstr  error message
  * @param string           $errfile file of the error
  * @param int              $errline line of the error
  *
  * @throws SoapFault
  */
 public static function errorHandlerForFatal($errno, $errstr, $errfile = null, $errline = null)
 {
     $code = self::$_defaultCode;
     self::stopErrorHandlerForFatal();
     if ($errstr instanceof Exception) {
         if ($errstr->getCode()) {
             $code = $errstr->getCode();
         }
         $errstr = $errstr->getMessage();
     } elseif (!is_string($errstr)) {
         $errstr = 'Unknown error';
     }
     throw new SoapFault($code, $errstr . ' (error [' . $errno . '])');
 }