What are the effects of exceptions on performance in Java?

前端 未结 17 2383
情深已故
情深已故 2020-11-22 01:21

Question: Is exception handling in Java actually slow?

Conventional wisdom, as well as a lot of Google results, says that exceptional logic shouldn\'t be used for n

17条回答
  •  后悔当初
    2020-11-22 01:41

    Why should exceptions be any slower than normal returns?

    As long as you don't print the stacktrace to the terminal, save it into a file or something similar, the catch-block doesn't do any more work than other code-blocks. So, I can't imagine why "throw new my_cool_error()" should be that slow.

    Good question and I'm looking forward to further information on this topic!

提交回复
热议问题