public static function Error::renderExceptionSafe

public static Error::renderExceptionSafe($exception)

Renders an exception error message without further exceptions.

Parameters

\Exception|\Throwable $exception: The exception object that was thrown.

Return value

string An error message.

File

core/lib/Drupal/Core/Utility/Error.php, line 87

Class

Error
Drupal error utility class.

Namespace

Drupal\Core\Utility

Code

public static function renderExceptionSafe($exception) {
  $decode = static::decodeException($exception);
  $backtrace = $decode['backtrace'];
  unset($decode['backtrace']);
  // Remove 'main()'.
  array_shift($backtrace);

  // Even though it is possible that this method is called on a public-facing
  // site, it is only called when the exception handler itself threw an
  // exception, which normally means that a code change caused the system to
  // no longer function correctly (as opposed to a user-triggered error), so
  // we assume that it is safe to include a verbose backtrace.
  $decode['@backtrace'] = Error::formatBacktrace($backtrace);
  return SafeMarkup::format('%type: @message in %function (line %line of %file). <pre class="backtrace">@backtrace</pre>', $decode);
}

© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.
https://api.drupal.org/api/drupal/core!lib!Drupal!Core!Utility!Error.php/function/Error::renderExceptionSafe/8.1.x