Generate the message for the exception

@param \Exception $exception The exception to log a message for.
@param bool $isPrevious False for original exception, true for previous
@return string Error message
495920
protected function getMessageForException($exception, $isPrevious = false)
    {
        $exception = $exception instanceof PHP7ErrorException ?
            $exception->getError() :
            $exception;
        $config = $this->_options;

        $message = sprintf(
            '%s[%s] %s in %s on line %s',
            $isPrevious ? "\nCaused by: " : '',
            get_class($exception),
            $exception->getMessage(),
            $exception->getFile(),
            $exception->getLine()
        );
        $debug = Configure::read('debug');

        if ($debug && method_exists($exception, 'getAttributes')) {
            $attributes = $exception->getAttributes();
            if ($attributes) {
                $message .= "\nException Attributes: " . var_export($exception->getAttributes(), true);
            }
        }

        if (!empty($config['trace'])) {
            $message .= "\nStack Trace:\n" . $exception->getTraceAsString() . "\n\n";
        }

        $previous = $exception->getPrevious();
        if ($previous) {
            $message .= $this->getMessageForException($previous, true);
        }

        return $message;
    }
1043083
protected function getErrorMessage(Exception $exception)
    {
        $defaultMessage =  __('Unexpected error. Please contact administrator');
        if (DEBUG_MODE) {
            $defaultMessage = $exception->getMessage();
        }
        return ($exception instanceof common_exception_UserReadableException) ? $exception->getUserMessage() :  $defaultMessage;
    }
1298311
public function getErrorMessage( bool $appendPreviousByNewline = false ) : string
   {

      // Getting a optional previous exception
      $prev = $this->getPrevious();

      if ( \is_null( $prev ) )
      {
         // If no previous exception is used
         return \sprintf(
            '%s(%d): %s',
            static::GetCodeName( $this->getCode() ),
            $this->getCode(),
            $this->getMessage()
         );
      }

      // Define the separator between current and previous exception.
      $separator = $appendPreviousByNewline ? "\n" : ' ';

      if ( ( $prev instanceof BelugaError ) )
      {
         return \sprintf(
            '%s(%d): %s%s%s',
            static::GetCodeName( $this->getCode() ),
            $this->getCode(),
            $this->getMessage(),
            $separator,
            $prev->getErrorMessage( $appendPreviousByNewline )
         );
      }

      return \sprintf(
         '%s(%d): %s%s%s',
         static::GetCodeName( $this->getCode() ),
         $this->getCode(),
         $this->getMessage(),
         $separator,
         $prev->getMessage()
      );

   }
712051
public function withException(\Exception $exception)
    {
        assert(!is_null($exception), 'Exception must not be null');

        return $this->withDetail('error', $exception->getMessage());
    }
237094
public function logException($exception)
    {
        $category = get_class($exception);
        if ($exception instanceof HttpException) {
            $category = 'Zilf\\web\\HttpException:' . $exception->statusCode;
        } elseif ($exception instanceof \ErrorException) {
            $category .= ':' . $exception->getSeverity();
        }
        Zilf::error($exception, $category);
    }
1193765
protected function _reportException($exception)
    {
        $msg = '`' . get_class($exception) .'` Code(' . $exception->getCode() . ') with ';
        $message = $exception->getMessage();
        if ($message) {
            $msg .= 'message '. Text::dump($exception->getMessage());
        } else {
            $msg .= 'no message';
        }
        $this->write("{$msg}\n\n");
    }
1092446
protected function exceptionMessage(\Exception $e)
    {
        return get_class($e) . ' in ' . $e->getFile() . ':' . $e->getLine() . ' "' . $e->getMessage() . '"';
    }
909255
private function logException($message, $exception)
    {
        return $this->app['logger.system']->error(
            $message . ': ' . $exception->getMessage(),
            ['event' => 'exception', 'exception' => $exception]
        );
    }
479349
public function formatException(\Exception $e) {
        $xml = new XMLWriter();
        $xml->openMemory();
        $xml->writeElement('class', get_class($e));
        $xml->writeElement('message', htmlspecialchars($e->getMessage(), ENT_QUOTES, 'UTF-8'));
        $xml->writeElement('file', htmlspecialchars($e->getFile(), ENT_QUOTES, 'UTF-8'));
        $xml->writeElement('line', $e->getLine());
        $xml->writeElement('trace', htmlspecialchars($e->getTraceAsString(), ENT_QUOTES, 'UTF-8'));

        return $xml->outputMemory();
    }
1309035
private function getMessage(\Exception $exception)
    {
        $message = $exception->getMessage();

        if ($this->isApiException($exception)) {
            $message = $exception->getMessageWithVariables();
        }

        return $message;
    }
546032
private static function hasPDOException(\Exception $exception)
    {
        if ($exception instanceof \PDOException) {
            return true;
        }
        if ($exception->getPrevious() === null) {
            return false;
        }
        return self::hasPDOException($exception->getPrevious());
    }
293889
protected function _addException(Exception $exception)
    {
        $this->_hasErrors = true;
        $this->_errorsList[$exception->getCode()] = [
            'message'   => $exception->getMessage(),
            'line'      => $exception->getLine(),
            'file'      => $exception->getFile(),
            'trace'     => $exception->getTraceAsString(),
        ];

        return $this;
    }
457470
public function getStatusCode(FlattenException $exception)
    {
        $str = '';
        if (method_exists($exception, 'getStatusCode') == true) {
            $str = $exception->getStatusCode();
        } elseif (method_exists($exception, 'getCode') == true) {
         $str = $exception->getCode();
        }

        return $str;
    }
299222
public function logException($exception, $extra = null)
    {
        // create a new AuditError
        $auditError = new AuditError;
        $auditError->created = time();
        $auditError->status = 'new';
        $auditError->code = ($exception instanceof CHttpException) ? $exception->statusCode : 500;
        $auditError->error_code = $exception->getCode();
        $auditError->type = get_class($exception);
        $auditError->message = $exception->getMessage();
        $auditError->trace = $exception->getTraceAsString();
        if ($extra) {
            $auditError->extra = AuditHelper::pack($extra);
        }

        // get file and line
        $exactTrace = $this->getExactTrace($exception);
        if (!$exactTrace) {
            $auditError->file = str_replace(array('/', '\\'), DIRECTORY_SEPARATOR, $exception->getFile());
            $auditError->line = $exception->getLine();
        } else {
            $auditError->file = str_replace(array('/', '\\'), DIRECTORY_SEPARATOR, $exactTrace['file']);
            $auditError->line = $exactTrace['line'];
        }
        $auditError->source_code = AuditHelper::pack($this->renderSourceCode($auditError->file, $auditError->line, $this->maxSourceLines));

        // get traces
        $trace = $exception->getTrace();
        if ($trace) {
            foreach ($trace as $i => $t) {
                if (!isset($t['file']))
                    $trace[$i]['file'] = 'unknown';
                $trace[$i]['file'] = str_replace(array('/', '\\'), DIRECTORY_SEPARATOR, $trace[$i]['file']);

                if (!isset($t['line']))
                    $trace[$i]['line'] = 0;

                if (!isset($t['function']))
                    $trace[$i]['function'] = 'unknown';

                if (isset($t['object']))
                    unset($trace[$i]['object']);
            }
        }
        $auditError->traces = json_encode($trace);
        $auditError->stack_trace = AuditHelper::pack($this->renderStackTrace($trace));

        // get the AuditRequest
        $auditRequest = $this->getAuditRequest();
        $auditError->audit_request_id = $auditRequest ? $auditRequest->id : 0;

        // generate a hash of the error
        $auditError->hash = $this->hash($auditError->message . $auditError->file . $auditError->line);

        // save the AuditError
        $auditError->save(false);
        return $auditError;
    }
1071082
private function serializeException(\Exception $exception)
    {
        $result = [
            'code'    => $exception->getCode(),
            'message' => $exception->getMessage(),
            'file'    => $exception->getFile(),
            'line'    => $exception->getLine(),
            'trace'   => $exception->getTraceAsString(),
        ];

        if ($exception->getPrevious() !== null) {
            $result['previous'] = $this->serializeException($exception->getPrevious());
        }

        return $result;
    }
10399
private function normalizeException(\Exception $exception) {
		$data = [
			'class'   => get_class($exception),
			'message' => $exception->getMessage(),
			'code'    => $exception->getCode(),
			'file'    => $exception->getFile() . ':' . $exception->getLine(),
		];
		$trace = $exception->getTraceAsString();
		$data['trace'] = $trace;

		$previous = $exception->getPrevious();
		if ($previous) {
			$data['previous'] = $this->normalizeException($previous);
		}

		return $data;
	}
642095
private function getNotificationMessage(Throwable $exception): string
    {
        if ($exception instanceof HttpExceptionInterface) {
            return $exception->getMessage();
        }

        $file = new SplFileInfo($exception->getFile());
        $line = $exception->getLine();

        $relativePathname = (new Filesystem())->makePathRelative($file->getPath(), $this->rootDir) . $file->getFilename();

        $message = $exception->getMessage();

        return sprintf('%s [in %s:%d]', $message, $relativePathname, $line);
    }