Get the App
SLTechnology News&Howtos  ›  Development  › 

How to solve the problem of java:try...catch skipping exceptions and continuing to deal with loops

Shulou Source: shulou.com Published: 2022-06-03 07:54:16 09月15日 Update

This article explains how to solve java:try. catch skips exceptions and continues to deal with loop problems."The explanation in this article is simple and clear, easy to learn and understand. Please follow the ideas of Xiaobian slowly and deeply to study and learn" how to solve java:try... catch Skip the exception and continue with the loop problem.

directory

problem description

the solution is simple

1. Catch exception Continue code execution

2. description

Java try catch shortcuts for handling exceptions

problem description

In the body of the code loop, the code stops executing after throwing an exception, causing the code to fail to run completely.

the solution is simple

Catch exceptions and simply handle them.

1. Catch exception Continue code execution

Paste only core sample code

public void getTest() { List list = new ArrayList(); list.add("1"); list.add("2"); list.add("e"); //an error will be thrown when turning numbers list.add("4"); for (String str : list) { try { int num = Integer.parseInt(str); //outlier System.out.println(num); } catch (Exception e) { e.printStackTrace(); //continue; } //finally {do something} System.out.println("***"); } }2. Description

In the above code, an exception will be thrown when the string is converted to a number. The code will catch the exception and print it out, and then continue to execute the rest of the code. If you don't want to continue executing the rest of the code, remove the logout of continue. Once an exception occurs, you will directly proceed to the next loop.

Java try catch shortcuts for handling exceptions

1. First, select the code block you want to add, right click, surround with appears, and then select try catch.

2. Of course you can press ctrl+shift+z and select after coming out.

3. Alt+/is the code prompt function in myeclipse, you just write a try and then press the alt key with your left hand. Don't let go of the right hand and press the/key. When myeclipse appears, release your hands and press enter (back).

Thank you for reading, above is "how to solve java:try... catch skip exception continue to handle loop problem "content, after learning this article, I believe everyone on how to solve java:try... Catch skips exceptions and continues to handle loop problems. This problem has a deeper understanding. The specific use situation still needs to be verified by practice. Here is, Xiaobian will push more articles related to knowledge points for everyone, welcome to pay attention!

Tags: Code problem processing loop learning content keyboard shortcuts numbers solutions tips selections functions hands right hands descendants characters strings that is left hand Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Microsoft OPPO Reno Shulou Technology Apple MariaDB