I'm trying to catch a PDOException in laravel 3 but it seems as if 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()));
}
The general exception is caught if the other parts in the 'try' throw an exception. If they do not, everything runs clean. If the create
has an issue executing the MYSQL statement it does not throw a PDOException, it is only throwing a general Exception.
PDOException
– Ultramicroscope$e
, egget_class($e)
? That will at least tell you the type of exception being caught in the general exception handler – AdjudicateMyobject
which seems to be relevant (you expect it to throw a PDOException!) so that people can easily reproduce the issue. – Suberthrow
ing, there's no way to answer this. – Rustication