You are here

public static function Error::suppress in Markdown 8.2

Suppresses any errors or exceptions while executing a callback.

Parameters

callable $callback: The callback to execute and suppress any errors or exceptions.

array $exceptions: An array of exceptions that were thrown, if any, passed by reference.

int $errorTypes: The error types to catch.

Return value

mixed|null The return value of the callback.

2 calls to Error::suppress()
InstallablePluginManager::processLibraryDefinition in src/PluginManager/InstallablePluginManager.php
Processes the library definition.
InstallablePluginTrait::validate in src/Annotation/InstallablePluginTrait.php
Validates the plugin requirements.

File

src/Util/Error.php, line 22

Class

Error

Namespace

Drupal\markdown\Util

Code

public static function suppress(callable $callback, array &$exceptions = [], $errorTypes = E_ERROR | E_RECOVERABLE_ERROR | E_USER_ERROR) {
  set_error_handler(function ($severity, $message, $file, $line) {
    throw new \ErrorException($message, 0, $severity, $file, $line);
  }, $errorTypes);
  $result = NULL;
  try {
    $result = $callback();
  } catch (\Throwable $exception) {
    $exceptions[] = $exception;
  } catch (\Exception $exception) {
    $exceptions[] = $exception;
  }
  restore_error_handler();
  return $result;
}