Java exception (Exception) processing and multithreaded startup

Source: Internet
Author: User

1.NumberFormatException exception, the writing process does not show errors, is handled by RuntimeException exception

 Public class Gty {    publicstaticvoid  main (string[] args) {                int a=integer.parseint ("123e");}    }

2. Generate an exception, the following statement does not hold the line

public class Gty {public    static void Main (string[] args) {                System.out.println ("start");         int A=integer.parseint ("123e");        int B=integer.parseint ("O"); Exception (Exception)           System.out.println ("2. Division calculation: "+ (A/b)); An exception is generated and the following statement does not execute        System.out.println ("End");}     }

Operation Result:

3.1 Try....catch Handling exception: "Catch exception", Sequential execution

//Print out statements are displayed in sequence when abnormal //finally{} code must be executed } System.out.println ("End");}}

  

Operation Result:

3.2 Try....catch Handling Exception: System comes with Printstacktrace () method to deal with exceptions, the principle of multithreading

//system provided, the display position is uncertain (multithreading principle);} finally {System.out.println ("code that will execute");//finally{} code must execute}SYSTEM.OUT.PRINTLN ("End");}}

 

Run result (a):

 

Operation Result (b):

4. How to start multi-threaded

Anonymous methods and anonymous content classes                } catch (Interruptedexception e) {//TODO auto-generated catch Blocke.printstacktrace ();} System.out.println ("in Progress");}). Start ();

  

Java exception (Exception) processing and multithreaded startup

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.