10.04.2018 Views

Doctrine_manual-1-2-en

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Chapter 30: Exceptions and Warnings 372<br />

Chapter 30<br />

Exceptions and Warnings<br />

Listing<br />

30-1<br />

Manager exceptions<br />

<strong>Doctrine</strong>_Manager_Exception is thrown if something failed at the connection<br />

managem<strong>en</strong>t<br />

try {<br />

$manager->getConnection('unknown');<br />

} catch (<strong>Doctrine</strong>_Manager_Exception) {<br />

// catch errors<br />

}<br />

Relation exceptions<br />

Relation exceptions are being thrown if something failed during the relation parsing.<br />

Connection exceptions<br />

Connection exceptions are being thrown if something failed at the database level. <strong>Doctrine</strong><br />

offers fully portable database error handling. This means that whether you are using sqlite or<br />

some other database you can always get portable error code and message for the occurred<br />

error.<br />

Listing<br />

30-2<br />

try {<br />

$conn->execute('SELECT * FROM unknowntable');<br />

} catch (<strong>Doctrine</strong>_Connection_Exception $e) {<br />

echo 'Code : ' . $e->getPortableCode();<br />

echo 'Message : ' . $e->getPortableMessage();<br />

}<br />

Query exceptions<br />

An exception will be thrown wh<strong>en</strong> a query is executed if the DQL query is invalid in some<br />

way.<br />

----------------- Brought to you by

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!