Pageviews

Monday 17 June 2013

Exception handling in Java

by Unknown  |  in Exception handling at  Monday, June 17, 2013

Exception handling is one of the most powerful features supported by high level programming languages.Java also support exception handling by providing 5 keywords to handle all kinds of exceptions.

Exception handling






Error:An Error is a condition in the program which may produce undesirable result or it may hinder the normal execution of the program.Errors,basically are of 3 types:

1.Compile time errors:The errors which ccurs during thecompilation of the program are called as Compile time errors.Eg:Variable not declared,Loop not initialized etc.

2.Run Time errors:The errors which occurs during the run time of a program are known as Run time errors.These errors interrupts the normal flow of execution of the program. Eg:divide by 0,Array index out of bound.

3.Logical errors:These types of errors are produced by the programmer itself,because our program gets compiled and run smoothly,but the error is in the logic of the program.Eg:If we used < insted of > or used / instead of \.

Exception handling in Java:Exceptions are the unwanted entities in our program,that interrupt the normal flow of program.Example:

Statement1;
Statement2;
Statement3;
Statement4;
Statement5;
Statement6;
Statement7;
Statement8;
Statement9;
Statement10;

Our program consists of 10 statements,if the error is in the statement 5,then the rest of the statements will not be executed,the program flow will be halted.Java supports Exception handling to control these exceptions.Some exceptions are automatically handled,but some are handled using the special keywords used in Exception handling.

Types of Exception handling:


  • Built in Classes
  • User defined exeptions


Built in Classes: The classes which are already defined in the Java are called as Built in exception classes.The root class for exceptions is Exception.All the exception classes are defined in the class exception.

User defined Exceptions:The exception classes which are defined by the user by inheriting the root exception class are known as User defined exception classes in Java. 

0 comments:

Proudly Powered by Blogger.