Answers for "drupal 8 try catch"

0

drupal 8 try catch

try {
  $id = $connection->insert('example')
    ->fields([
      'field1' => 'mystring',
      'field2' => 5,
    ])
    ->execute();

  my_other_function($id);

  return $id;
}
catch (Exception $e) {
  // Something went wrong somewhere, so roll back now.
  $txn->rollBack();
  // Log the exception to watchdog.
  \Drupal::logger('type')->error($e->getMessage());
}
Posted by: Guest on June-30-2021

Browse Popular Code Answers by Language