Cannot catch PDOException in laravel 3

I am trying to catch a PDOException in laravel 3, but it seems like I cannot do this. My code is as follows:

try{ DB::connection()->pdo->beginTransaction(); Myobject::create($cleaned_input_array); // do other stuff that could possibly throw a custom exception DB::connection()->pdo->commit(); } catch(\PDOException $e) { DB::connection()->pdo->rollBack(); return HTTP_STATUS::response(BAD_REQUEST, array("error creating"); } catch(Exception $e) { DB::connection()->pdo->rollBack(); return HTTP_STATUS::response(BAD_REQUEST, array($e->getMessage())); } 

A general exception is caught if the other parts in the "try" throw an exception. If they do not, everything will be clean. If create has a problem executing a MYSQL statement, it does not throw a PDOException, it only throws a general exception.

+6
source share
1 answer

The model would not actually throw a PDOException that would be caught internally, but instead would have \Illuminate\Database\QueryException , try to catch this.

-1
source

All Articles