Should java try blocks be scoped as tightly as possible?

后端 未结 7 1787
孤城傲影
孤城傲影 2020-12-01 00:35

I\'ve been told that there is some overhead in using the Java try-catch mechanism. So, while it is necessary to put methods that throw checked exception within a try block t

7条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-01 01:29

    I've been told that there is some overhead in using the Java try-catch mechanism.

    Absolutely. And there's overhead to method calls, too. But you shouldn't put all your code in one method.

    Not to toot the premature optimization horn, but the focus should be on ease of reading, organization, etc. Language constructs rarely impact performance as much as system organization and choice of algorithms.

    To me, the first is easiest to read.

提交回复
热议问题