Try-catch Example

Source: Internet
Author: User

 Packageunit5;ImportJava.util.Scanner;ImportJavax.print.CancelablePrintJob;ImportJavax.sound.midi.SysexMessage;ImportUnit4.interfacedemo; Public classTrycatchdemo { Public Static voidMain (string[] args) {intA=0,b=0,c=0; Try{a=integer.parseint (args[0]); b=integer.parseint (args[1]); C=a/b; System.out.println ("C=" +c); System.out.println ("* * Normal Execution"); System.out.println ("Real division does not produce a mathematical class exception: 3.0/0.0" + (3.0/0.0)); } Catch(arrayindexoutofboundsexception E1) {System.out.println ("This program requires two parameters!"); }Catch(numberformatexception E2) {System.out.println ("There must be numbers."); }Catch(ArithmeticException e3) {System.out.println ("Divisor cannot be zero"); System.out.println ("Please re-enter parameters"); Scanner in=NewScanner (system.in); b=In.nextint (); C=a/b; System.out.println ("C=" +c); }    }}

Try-catch Example

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.