/**
  * Will always execute after any/all migrations have run. The purpose of this is to clean up and to handle any
  * unexpected errors which may occur.
  *
  * @param   Exception|null $e
  */
 public function shutdown(Exception $e = null)
 {
     // Run once.
     if ($this->shutdown) {
         return;
     }
     $this->shutdown = true;
     // Revert back to previous error handling.
     restore_error_handler();
     // If there's an error but no exception, setup an exception now for reporting purposes.
     if ($this->error && !$e) {
         $e = new MigrationException("The migration" . ($this->lastMigrationFile ? " '{$this->lastMigrationFile}.php'" : "") . " terminated unexpectedly.");
     }
     if ($e) {
         // Rollback database changes and notify user.
         DB::getConn()->transactionRollback();
         $this->output("ERROR" . ($e->getCode() != 0 ? " (" . $e->getCode() . ")" : "") . ": " . $e->getMessage());
         $this->output("\nNote: Any database changes have been rolled back.");
         $this->output("\nStack Trace:");
         $this->output($e->getTraceAsString());
         exit(1);
     }
 }
 /**
  * Constructs the exception with the erroneous query
  *
  * @param string $query
  * @param string $message [optional] The Exception message to throw.
  * @param int $code [optional] The Exception code.
  * @param \Exception $previous [optional] The previous exception used for the exception chaining. Since 5.3.0
  */
 public function __construct($query = 'NOT PROVIDED', $message = '', $code = 0, \Exception $previous = null)
 {
     $message = sprintf($this->message, $query);
     parent::__construct($message, $code, $previous);
 }