First of all, you shouldn't need to wrap all calls to exception throwing functions in a try/catch block. Doing that is not much different that checking return error codes. You should catch exceptions where you can appropriately deal with them, not where they are being thrown. There is no use in catching an exception if you can't do anything useful with it. But to not catch an exception when you can deal with it (and possibly save the program from die-ing) is a design-time error not a compile/run-time error.

I agree too with adrianh, you probably need some static code analysis, and then have a talk about exceptions with all your developers to agree upon a method of usage. Consistent usage/paradigms is very important among groups of developers IMHO.

Secondly, If your program is throwing uncaught exceptions and die-ing, then wrap the main entry point in a try block. This will allow you to at least catch these exceptions and print out a stack trace before your program dies. Of course this may not be the best place to handle your exceptions, but at the very least you can do something rather than just letting things die.

Of course I am speak of Perl, not Java (which IMHO has got alot of language design problems). If you want a non-Perl reference to how to handle exceptions, don't look at Java instead look at a language like Ada. Java was made for web-applets, Ada was made by the U.S. Dept. of Defense for missle guidance systems (where reliability and smart error handling is key).

-stvn

In reply to Re: Enforcing exception catching by stvn
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.