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 All Tutorials

 
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
 
Java
  JDO Tutorials
  EAI Articles
  Struts Tutorials
  Java Tutorials
  Java Certification
  Java Applet
Questions
Comments

Exception Handling

                         

Exceptions:
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);
    }
  }
}

Output of this program:

C:\vinod\xml>javac exceptionHandle.java

C:\vinod\xml>java exceptionHandle

For input string: "" is not a numeric value.


An exception is an event that occurs and  interrupts the normal flow of instructions. That is exceptions are objects that store the information about the occurrence of errors. When any kind of error or unusual condition occurs, these exceptions are being thrown. Any exception used to occur earlier always resulted in a program crash. However, some programming languages like java have mechanisms for handling exceptions. This is known as catching exception in Java. The exceptions that occur in the program can be caught using try and catch block.  Remember, the program will crash if the exception would not be caught. There are three types of exceptions in Java. These are -:

1. Checked Exceptions
2. The error
3. Runtime exception

Error and Runtime exceptions are known as unchecked exceptions. This chapter covers how to throw an exception and catch it.
A detailed explanation on the types of exceptions and the advantages of the exceptions.

Basic I/O:
In this section we will learn about basic input and out put operations in Java. Different kinds of sources and destinations are represented by a Stream like disk files, devices, memory arrays etc.  A Stream is a sequence of data. An Input Stream is used by the program to read data from the source. Similarly, a program uses an Output stream to write data to a destination. It also supports different kinds of data including simple bytes, primitive data types, objects etc. We will learn about I/O Steams and how to use them. 

Concurrency:
Concurrency is generally used to perform multiple tasks simultaneously. In this section we will learn how to write applications to perform multitasking. There are two types of units of execution process and threads. Thread is the most important unit in concurrent programming. There are many processes and threads which are active in a computer system. However only one threads executes at a time even in systems that only have a single execution core.

Regular expression
The set of strings which are based on common characteristics are shared by each string in the set. Basically, Regular expressions are are a set of strings. 

This regular expression as a Java string, becomes "\\\\". That is 4 backslashes to match a single one. As in literal Java strings the backslash is an escape character. The literal string as a single backslash is denoted by "\\". In this chapter we will learn to create a syntax for regular expressions and how to use them.

                         

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

Current Comments

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

this site really a gift!!!!

Posted by sparsh on Saturday, 05.10.08 @ 12:30pm | #59083

Hello ji !

Really this is amazing site to read for freshers and experience condidates.......i cannot say thank u for this........because i will say that then i m insulting myself.......i have no words in my dictionary for this site..........

Posted by Dinesh Kumar on Tuesday, 04.1.08 @ 15:51pm | #55038

Hi..
Very nice nice topic.
Its really very helpful.

Thanks
harikesh

Posted by Harikesh on Thursday, 10.11.07 @ 18:01pm | #33069

Leave your comment:

Name:

Email:

URL:

Title:

Comments:


Enter Code:

 

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.

Hot Web Programming Job

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

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

Copyright © 2007. All rights reserved.