The old approach: returning special error values or setting some kind of flag basically s**ks. The biggest problem with this way is that you can ignore the errors (you don't even have to do anything for that!). Take for example printing to a file. It's too easy not to check for errors and assume everything went fine. And if you do handle the errors this way you can get a mix-up of error handling code with code that does the actual work. Also if you want to give the caller a chance to recover from the error this might be impossible. All the caller will get is a flag indicating the error or some string.

The exception handling mechanism is much more elegant. It gives a better way of handling errors; you can not ignore errors but are forced do handle them, it leads to more maintainable code and you can basically return * any * type of data you want. Errors might be related, you could set up a hierarchy of exceptions. Try do that the old fashioned way. IMO exception handling is the superior way of error handling. Look at languages like Ada (one of the first with this feature), C++/# or Java. They all have it and for good reason.


In reply to Re: Advantage of Exception handling in perl by dHarry
in thread Advantage of Exception handling in perl by vinoth.ree

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.