Surprisingly, following the latest OO conventions has led to serious problems and this question of mine

The niggler in me has to point out that the problem isn't really anything to do with exceptions - but with the change over. You would have the same problem in reverse if you were switching from exceptions to return values.

Is there a way to force calling functions to place calls to things that can throw exceptions in try{} block? (And I know the answer is probably "no"). Java has this type of enforcement built into the compiler.

If by "force" you mean give a compile-time error if you don't (as Java does for checked exceptions) then the answer is no. You can't get enough information at compile time because of Perl's dynamic nature.

Just as a point of information there are a fair number of people (myself included) who think Java's checked exceptions were an interesting but failed experiment. See Does Java need Checked Exceptions? and Checked Exceptions Are Of Dubious Value for some thoughts on this.

If there's no programmatic way of enforcing the practice, I'd like to hear how to cope with this besides preaching diligence to every member of the team -- people can still make mistakes.

During the changeover maybe some static code analysis would be a good idea. Grep through the sources for the method calls that can cause exceptions and do manual checks and code reviews.

In the longer term the best solution (and this applies to exceptions and return values) would be to improve your test suites so that it exercises the error handling code more. Use mock-objects to generate exceptions in situ and check that your application handles them appropriately.


In reply to Re: Enforcing exception catching by adrianh
in thread Enforcing exception catching by dmitri

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.