You wrote:

"okay, let them to return the special sign to the caller and the caller will report to its' caller and so on - until the process pop up to the main module."

But perhaps you might have said instead: "let them to return the special sign to the caller and the caller will report to its' caller and so on - until it reaches a level I forgot to check for the special sign."

Exceptions are a special sign. But they are a special sign that you cannot forget to pass to your caller because Perl automatically passes it up and up and up until it finds a caller that is willing to do something useful with the special sign (i.e. catch the exception).

So throw exceptions! Don't return special signs!

If every level of caller needs knowledge about your "special signs", then your callers have too much knowledge about your class. Your callers have become tightly coupled to your class. This is bad.

"But I think the descision to die() can have only the main module."

I think you're confusing the decision to die() with the decision to exit(). I absolutely agree that the main script should be making the decision about when it exits. However, as you know, calling die() does not necessarily cause the script to exit; it can be caught by any level of caller and handled gracefully. It only causes the script to exit if an error occurs that nothing is able to handle.


In reply to Re^3: Using die() in methods by tobyink
in thread Using die() in methods by v_melnik

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.