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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |