An instance of java--exception handling

Source: Internet
Author: User
/* Time:
	2012-10-10
Author:
	Smoke large
program requirements:
	familiar with the exception handling mechanism;
	Try
	{
		The code that may appear to be abnormal;
	}
	catch
	{
		actions to handle exceptions;
	}
	finally {The
		action that must be performed;
	}
Program Explanation:
	First: Write the code for the input, In the previous example, we have also given example
	two: Write try{}catch{}finally{} 's internal code part
	three: Finally through the value of I to judge the abnormal output operation/
import java.io .*;
Class Day1010_exception 
{public
	static void Main (string[] args) throws IOException
	{
		String name;
		int i=0;
		
		Try
		{
			BufferedReader b;
			B=new BufferedReader (New InputStreamReader (system.in));
			Name=b.readline ();
			Name=args[0];
			System.out.println ("Dear" +name+) hello. ");
			i=0;
		}
		catch (arrayindexoutofboundsexception e)
		{
			i=1;
		}
		Finally
		{
			if (i==1)
			{
				System.out.println ("Please enter a name.) ");
			}
		}
		
	}
}

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.