Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
In Java and C++, exceptions are typically instances of some class, and are "thrown" by bad code and caught in surrounding "try/catch" syntax.

While some people have built these elaborate synonymous structures using Perl packages, I have found very little advantage in them over using Perl's built-in exception mechanism.

In Perl, exceptions are a scalar value, stored in the special variable $@. These exceptions are "thrown" by bad code using the keyword die and caught in surrounding code by eval { } syntax.

The advantages of classes appears to be when there are so many possible causes of failure that you need to send back uber-complex reporting structures to attempt to explain it. If you don't need all this complexity (and you should always avoid undue complexity), just use die/eval.

Write Perl in Perl idioms using Perl's mechanisms. Otherwise you're just coding in Java or C++, but sprinkled with funny sigils.

[ e d @ h a l l e y . c c ]

In reply to Re: Exception Classes Advice on Subclasses by halley
in thread Exception Classes Advice on Subclasses by jffry

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, 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, 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.
  • Log In?

    What's my password?
    Create A New User
    [marto]: good morning all
    [Corion]: Hi marto!

    How do I use this? | Other CB clients
    Other Users?
    Others musing on the Monastery: (9)
    As of 2018-05-24 07:18 GMT
    Find Nodes?
      Voting Booth?