<!-- 
RSS generated by JIRA (5.2.7#850-sha1:b2af0c8dc8537b36121c6a579fabbdf79fc919e5) at Wed Jun 19 13:34:56 UTC 2013

It is possible to restrict the fields that are returned in this document by specifying the 'field' parameter in your request.
For example, to request only the issue key and summary add field=key&field=summary to the URL of your request.
For example:
http://www.doctrine-project.org/jira/si/jira.issueviews:issue-xml/DBAL-407/DBAL-407.xml?field=key&field=summary
-->
<rss version="0.92" >
<channel>
    <title>Doctrine Project</title>
    <link>http://www.doctrine-project.org/jira</link>
    <description>This file is an XML representation of an issue</description>
    <language>en-us</language>    <build-info>
        <version>5.2.7</version>
        <build-number>850</build-number>
        <build-date>21-02-2013</build-date>
    </build-info>

<item>
            <title>[DBAL-407] Refactor exceptions</title>
                <link>http://www.doctrine-project.org/jira/browse/DBAL-407</link>
                <project id="10040" key="DBAL">Doctrine DBAL</project>
                        <description>&lt;p&gt;It&apos;s currently rather hard to figure out what went wrong when for example a DBALException was thrown. You have to actually match the message in it, or read the status code of the -&amp;gt;getPrevious() exception, which can be different for all drivers (as &lt;a href=&quot;https://github.com/jackalope/jackalope-doctrine-dbal/issues/80&quot; class=&quot;external-link&quot;&gt;https://github.com/jackalope/jackalope-doctrine-dbal/issues/80&lt;/a&gt; shows).&lt;/p&gt;

&lt;p&gt;I&apos;d suggest creating new exception classes for all situations and throwing them instead. If they extend the DBAL Exception and pass the message to it as it is right now, there will be no BC break.&lt;/p&gt;

&lt;p&gt;If this were to be done, on which branch should this be applied?&lt;/p&gt;</description>
                <environment></environment>
            <key id="14355">DBAL-407</key>
            <summary>Refactor exceptions</summary>
                <type id="4" iconUrl="http://www.doctrine-project.org/jira/images/icons/issuetypes/improvement.png">Improvement</type>
                                <priority id="3" iconUrl="http://www.doctrine-project.org/jira/images/icons/priorities/major.png">Major</priority>
                    <status id="1" iconUrl="http://www.doctrine-project.org/jira/images/icons/statuses/open.png">Open</status>
                    <resolution id="-1">Unresolved</resolution>
                    <security id="10000">All</security>
                        <assignee username="beberlei">Benjamin Eberlei</assignee>
                                <reporter username="burgov">Bart van den Burg</reporter>
                        <labels>
                    </labels>
                <created>Mon, 7 Jan 2013 18:09:34 +0000</created>
                <updated>Mon, 6 May 2013 06:10:18 +0000</updated>
                                                                    <component>Drivers</component>
                <component>Platforms</component>
                <component>Schema Managers</component>
                        <due></due>
                    <votes>1</votes>
                        <watches>4</watches>
                        <comments>
                    <comment id="19251" author="stof" created="Mon, 7 Jan 2013 19:32:17 +0000"  >&lt;p&gt;This should be done in the master branch.&lt;/p&gt;

&lt;p&gt;Another solution, avoiding to create many classes, would be to use the exception code, which is always kept as 0 currently (the default value of the Exception class). You could have a code for each case (with constants in the DBALException class) and then checking &lt;tt&gt;$e-&amp;gt;getCode()&lt;/tt&gt; to identify what went wrong.&lt;/p&gt;</comment>
                    <comment id="19252" author="burgov" created="Mon, 7 Jan 2013 20:09:55 +0000"  >&lt;p&gt;I&apos;d prefer actual named exceptions. It makes catching them simpler. However, adding some code defined in DBAL would be an acceptable alternative. &lt;/p&gt;

&lt;div class=&quot;code panel&quot; style=&quot;border-width: 1px;&quot;&gt;&lt;div class=&quot;codeContent panelContent&quot;&gt;
&lt;pre class=&quot;code-java&quot;&gt;
&lt;span class=&quot;code-keyword&quot;&gt;try&lt;/span&gt; {
    /* ... /*
} &lt;span class=&quot;code-keyword&quot;&gt;catch&lt;/span&gt; (NoSuchTableException $e) {
    &lt;span class=&quot;code-comment&quot;&gt;// &lt;span class=&quot;code-keyword&quot;&gt;do&lt;/span&gt; something
&lt;/span&gt;} &lt;span class=&quot;code-keyword&quot;&gt;catch&lt;/span&gt; (DuplicateKeyException $e) {
    &lt;span class=&quot;code-comment&quot;&gt;// &lt;span class=&quot;code-keyword&quot;&gt;do&lt;/span&gt; something &lt;span class=&quot;code-keyword&quot;&gt;else&lt;/span&gt;
&lt;/span&gt;}
&lt;/pre&gt;
&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;v.s.&lt;/p&gt;

&lt;div class=&quot;code panel&quot; style=&quot;border-width: 1px;&quot;&gt;&lt;div class=&quot;codeContent panelContent&quot;&gt;
&lt;pre class=&quot;code-java&quot;&gt;
&lt;span class=&quot;code-keyword&quot;&gt;try&lt;/span&gt; {
    /* ... /*
} &lt;span class=&quot;code-keyword&quot;&gt;catch&lt;/span&gt; (DBALException $e) {
    &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; ($e-&amp;gt;getCode() == DBALException::NO_SUCH_TABLE) {
        &lt;span class=&quot;code-comment&quot;&gt;// &lt;span class=&quot;code-keyword&quot;&gt;do&lt;/span&gt; something
&lt;/span&gt;    } elseif ($e-&amp;gt;getCode() == DBALException::DUPLICATE_KEY) {
        &lt;span class=&quot;code-comment&quot;&gt;// &lt;span class=&quot;code-keyword&quot;&gt;do&lt;/span&gt; something &lt;span class=&quot;code-keyword&quot;&gt;else&lt;/span&gt;
&lt;/span&gt;    } &lt;span class=&quot;code-keyword&quot;&gt;else&lt;/span&gt; {
        &lt;span class=&quot;code-keyword&quot;&gt;throw&lt;/span&gt; $e;
    }
}
&lt;/pre&gt;
&lt;/div&gt;&lt;/div&gt;</comment>
                    <comment id="20217" author="chrisguitarguy" created="Mon, 6 May 2013 03:29:45 +0000"  >&lt;p&gt;I would also prefer named exceptions. You&apos;re going to have a lot of problems providing the &quot;code&quot; value in DBALException in any case: SQLSTATE codes are alphanumeric, and will cause warnings/errors when creating new exception.&lt;/p&gt;

&lt;p&gt;Besides we can get the SQL state code now:&lt;/p&gt;

&lt;div class=&quot;preformatted panel&quot; style=&quot;border-width: 1px;&quot;&gt;&lt;div class=&quot;preformattedContent panelContent&quot;&gt;
&lt;pre&gt;    try {
        // ...
    } catch (\Doctrine\DBAL\DBALException $e) {
        $code = $e-&amp;gt;getPrevious()-&amp;gt;getCode();
        // do stuff with $code
    }
&lt;/pre&gt;
&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;The problem is that there are a lot of error codes defined in the ANSI SQL standard: &lt;a href=&quot;http://www.postgresql.org/docs/9.2/static/errcodes-appendix.html&quot; class=&quot;external-link&quot;&gt;http://www.postgresql.org/docs/9.2/static/errcodes-appendix.html&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Maybe throwing an specific exception for each &quot;class&quot; of SQLSTATE codes? So if the error code from a PDO exception starts with 23, DBAL would throw `\Doctrine\DBAL\Exception\IntegrityConstraintViolationException`.&lt;/p&gt;

&lt;p&gt;This also seems like the logic to handle throwing exceptions should be contained in the platforms as some implementations may differ. You could have a method in `AbstractPlatform` that takes care of the ANSI SQLSTATE error code classes and leave it up subclasses to deal with platform specific cases. Whenever `Connection` catches a `PDOException`, dispatch it to the platform to deal with.&lt;/p&gt;

&lt;p&gt;Example: &lt;a href=&quot;https://gist.github.com/chrisguitarguy/e021918900e93dca304d&quot; class=&quot;external-link&quot;&gt;https://gist.github.com/chrisguitarguy/e021918900e93dca304d&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Thoughts?&lt;/p&gt;</comment>
                    <comment id="20218" author="mnapoli" created="Mon, 6 May 2013 06:09:52 +0000"  >&lt;p&gt;I have implemented a thing of that kind in a personal project (on top of Doctrine). It is &lt;b&gt;really&lt;/b&gt; useful to be able to catch a ForeignKeyViolationException, and get with entity/field caused the problem (for that my EntityManager wrapper parse the exception message).&lt;/p&gt;

&lt;p&gt;However, note that exception codes differ from DB engines. In my case, I did it quick and used MySQL error codes, but managing different RDBMS implies more work.&lt;/p&gt;</comment>
                </comments>
                    <attachments>
                </attachments>
            <subtasks>
        </subtasks>
        </item>
</channel>
</rss>