Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I generally prefer exceptions if you're indicating an error of some kind. Otherwise you have to spend much more time sprinkling error handling code at different levels of your codebase rather than centralising the error handling in appropriate layers of the system - amongst other reasons.</p> <p>You may find this <a href="http://www.perlmonks.org/?node_id=230799" rel="nofollow noreferrer">old thread on perlmonks</a> a useful read. I'll reproduce my comment there below - since I mostly agree with what I wrote back then :-)</p> <hr> <p>Some reasons I like exceptions:</p> <ul> <li><p>Robustness. I can forget to check for an returned error value. I cannot forget to check for an exception.</p></li> <li><p>Brevity. I prefer:</p> <pre><code>$o-&gt;foo-&gt;bar-&gt;fribble-&gt;ni </code></pre> <p>to</p> <pre><code>$o-&gt;foo or return(ERROR_FOO); $o-&gt;bar or return(ERROR_BAR); $o-&gt;fribble or return(ERROR_FRIBBLE); $o-&gt;ni or return(ERROR_NI); </code></pre></li> <li><p>Clarity. With exception based code the "normal" flow of control is more explicit because it is not obscured by error handling code. I think that the first of the two code examples above shows the intent of the code more directly than the second does.</p></li> <li><p>Separation of concerns. The error condition and the error handler are different ideas.</p> <ul> <li><p>You may want an error to be handled in different ways depending on the context.</p></li> <li><p>You may also not know how the error should be handled at the point it occurs.</p></li> <li><p>You may not know how the error should be handled at the time you write the code.</p></li> </ul> <p>With the return-error-code style you end up having to either:</p></p> <ul> <li><p>propogate error conditions to where the decision on how they should be handled can be made.</p></li> <li><p>propogating error handlers down to where the errors may occur</p></li> </ul> <p>Both options rapidly become messy if there are many levels of code between the error condition and the error handler.</p></p></li> <li><p>No confusion between return values and error conditions.</p></li> </ul> <p>There are probably some more ;-)</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload