Performance cost of coding “exception driven development” in Java?

前端 未结 14 1687
生来不讨喜
生来不讨喜 2020-12-09 10:28

Are there are any performance cost by creating, throwing and catching exceptions in Java?

I am planing to add \'exception driven development\' into a larger project.

14条回答
  •  悲&欢浪女
    2020-12-09 10:50

    Exceptions cost a lot because each time an exception is thrown, the stack trace must be created and populated.

    Imagine a balance transfer operation which fails in 1% of cases due to lack of funds. Even with this relatively little rate of failures, performance may be severely impacted. See here for the source code and benchmark results.

提交回复
热议问题