Throwing exceptions in Java

后端 未结 11 957
萌比男神i
萌比男神i 2020-12-30 16:23

I have a question about throwing exceptions in Java, a kind of misunderstanding from my side, as it seems, which I would like to clarify for myself.

I have been read

11条回答
  •  长发绾君心
    2020-12-30 16:42

    Using an exception for control flow is specifically dealt with in Effective Java, 2nd Edition by Joshua Bloch, Item 57:

    Item 57: Use exceptions only for exceptional conditions

    ...exceptions are, as their name implies, to be used only for exceptional conditions; they should never be used for ordinary control flow. [italics mine]

    So while it certainly "works" to use exceptions to control flow, it is not recommended.

提交回复
热议问题