diff --git a/src/Illuminate/Database/Connection.php b/src/Illuminate/Database/Connection.php index 7203b8efd601..24465134f377 100755 --- a/src/Illuminate/Database/Connection.php +++ b/src/Illuminate/Database/Connection.php @@ -646,14 +646,16 @@ public function pretend(Closure $callback) return $this->withFreshQueryLog(function () use ($callback) { $this->pretending = true; - // Basically to make the database connection "pretend", we will just return - // the default values for all the query methods, then we will return an - // array of queries that were "executed" within the Closure callback. - $callback($this); - - $this->pretending = false; - - return $this->queryLog; + try { + // Basically to make the database connection "pretend", we will just return + // the default values for all the query methods, then we will return an + // array of queries that were "executed" within the Closure callback. + $callback($this); + + return $this->queryLog; + } finally { + $this->pretending = false; + } }); }