Using update hook in Drupal 7

Submitted by aburrows on Mon, 12/12/2016 - 15:07

When using an update hook (hook_update_N) in Drupal 7, always wrap it with a try and catch function. This reduces database issues and if theres a syntax error in the code it will stop the code from executing.

function mymodule_update_7000() {
  try {
    // Execute code.
  catch (Exception $e) {
    throw $e->getMessage();