Home | Ajax | BioInformatics | Dojo | EAI | EJB | Hibernate | J2ME | Java | Java Glossary | Java Servlets | JavaScript | Jboss | JDBC | JDO | Jmeter | JSF | JSP | JUnit | Maven | MySQL | Spring Framework | SQL | Struts | Technology | WAP | Web Services | XML

Search:
   Programming Tutorials: Ajax | Articles | JSP | Bioinformatics | Database | Free Books | Hibernate | J2EE | J2ME | Java | JavaScript | JDBC | JMS | Linux | MS Technology | PHP | RMI | Web-Services | Servlets | Struts | UML Facing Programming Problem? Ask Questions?, Browse Latest Questions, Question-Answer Guidelines
Java
  JDO Tutorials
  EAI Articles
  Struts Tutorials
  Java Tutorials
  Java Certification
  Java Applet
Questions
Comments
Java Exception - Exception Handling in Java
In this section, you will learn to the exception handling.
 
 

Java Exception - Exception Handling in Java

                         

Exception, that means exceptional errors. Actually exceptions are used for handling errors in programs that occurs during the program execution. During the program execution if any error occurs and you want to print your own message or the system message about the error then you write the part of the program which generate the error in the try{} block and catch the errors using catch() block. Exception turns the direction of normal flow of the program control and send to the related catch() block. Error that occurs during the program execution generate a specific object which has the information about the errors occurred in the program.

In the following example code you will see that how the exception handling can be done in java program. This example reads two integer numbers for the variables a and b. If you enter any other character except number ( 0 - 9 ) then the error is caught by NumberFormatException object. After that ex.getMessage() prints the information about the error occurring causes.

Code of the program : 

import java.io.*;

public class exceptionHandle{
  public static void main(String[] args) throws Exception{
    try{
 
     int a,b;
      BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
      a = Integer.parseInt(in.readLine());
      b = Integer.parseInt(in.readLine());
    }
    catch(NumberFormatException ex){
      System.out.println(ex.getMessage() + " is not a numeric value.");
      System.exit(
0);
    }
  }
}

Download Exception Handling Example

                         

Leave your comment:

Name:

Email:

URL:

Title:

Comments:


Enter Code:

Audio Version
Reload Image
 

Note: Emails will not be visible or used in any way, and are not required. Please keep comments relevant. Any content deemed inappropriate or offensive may be edited and/or deleted.

No HTML code is allowed. Line breaks will be converted automatically. URLs will be auto-linked. Please use BBCode to format your text.

Add This Tutorial To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 

Current Comments

8 comments so far (
post your own) View All Comments Latest 10 Comments:

i need to know te difference between the catched exception and un catched exception.
It would be helpful if u post with some examples.

Posted by Arun on Monday, 10.13.08 @ 17:44pm | #81048

simply gr8.............but i miss a interactive forum......any chance of that?????

Need some ques 4 the experts also....would be gr8 if they answer

Posted by dip on Saturday, 01.12.08 @ 10:41am | #45031

Explanation of conception is short and excellient.

Posted by Sachin on Monday, 10.1.07 @ 10:27am | #30804

it's very good site.this is use for that even who is using the java for the first time can easily understand it.

Posted by swapna on Monday, 08.20.07 @ 14:55pm | #23772

This is really a nice site for beginners of Java> Every thing is described in a very easy Manner so that even a person who is using the java for the first time can easily understand it.

Posted by Amrit pal singh on Friday, 04.13.07 @ 15:41pm | #14098

Hey, this is an excellent site for JAVA developers who started their career .. excellent one .. Congrats to the roseindia site-masters for maintaning this one

Posted by rengith on Saturday, 03.17.07 @ 12:52pm | #11975

its good but very old patterned programs are there . plz make it new as it relfects the real world.

Posted by murali on Friday, 03.16.07 @ 16:54pm | #11915

In this program why u r giving String name here.

Posted by Mathivanan on Friday, 11.24.06 @ 13:27pm | #74

Java String toLowerCase Example
Java String toCharArray Example
Java String substring Example
Java String indexOf Example
Java String startsWith Example
Java String hashCode Example
Java String matches Example
Java String length Example
Java String lastIndexOf Example
Java String isEmpty Example
Java String equalsIgnoreCase Example
Java String equals Example
Java String endsWith Example
Java String copyValueOf Example
Java String contentEquals Example
  EAI Articles
  Java Certification
Tell A Friend
Your Friend Name
Search Tutorials

 

 
 
Browse all Java Tutorials
Java JSP Struts Servlets Hibernate XML
Ajax JDBC EJB MySQL JavaScript JSF
Maven2 Tutorial JEE5 Tutorial Java Threading Tutorial Photoshop Tutorials Linux Technology
Technology Revolutions Eclipse Spring Tutorial Bioinformatics Tutorials Tools SQL
 

Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Search Engine | News Archive | Jboss 3.0 tutorial | Free Linux CD's | Forum | Blogs

About Us | Advertising On RoseIndia.net  | Site Map

India News

Indian Software Development Company | iPhone Development Company in India | Java Training Delhi | Java Training at Noida |

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright © 2008. All rights reserved.