While digging into the exception handling of Doctrine, I stumbled on this code example that made me wonder out loud if this was overkill or could be of some use:
// Save entity
try {
$em->persist($someEntity);
$em->flush();
$this->logger->info("Saved someEntity");
} catch (DBALException $e) {
$this->logger->addError("DBALException [{code}]: {message}",
array('code' => $e->getCode(), $e->getMessage()));
} catch (PDOException $e) {
$this->logger->addError("PDOException [{code}]: {message}",
array('code' => $e->getCode(), $e->getMessage()));
} catch (ORMException $e) {
$this->logger->addError("ORMException [{code}]: {message}",
array('code' => $e->getCode(), $e->getMessage()));
} catch (Exception $e) {
$this->logger->addError("Exception [{code}]: {message}",
array('code' => $e->getCode(), $e->getMessage()));
}
I always just used the generic exception (the last in code example), and was wondering if this is overkill in most cases unless one wants to handle one of the defined exception differently?