How can I break from a try/catch block without throwing an exception in Java

后端 未结 6 1413
感动是毒
感动是毒 2021-02-01 12:29

I need a way to break from the middle of try/catch block without throwing an exception. Something that is similar to the break and continue in for loops. Is this possible?

6条回答
  •  [愿得一人]
    2021-02-01 12:53

    There are several ways to do it:

    1. Move the code into a new method and return from it

    2. Wrap the try/catch in a do{}while(false); loop.

提交回复
热议问题