Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

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

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

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!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report