Exception Classes in Java


Prev Tutorial Next Tutorial

Exception Classes in Java

Exception are mainly classified into two type checked exception and un-checked exception.

Checked Exception Classes

  • FileNotFoundException
  • ClassNotFoundException
  • IOException
  • InterruptedException

Un-Checked Exception Classes

  • ArithmeticException
  • ArrayIndexOutOfBoundsException
  • StringIndexOutOfBoundsException
  • NumberFormateException
  • NullPointerException
  • NoSuchMethodException
  • NoSuchFieldException


If the given filename is not available in a specific location ( in file handling concept) then FileNotFoundException will be raised. This exception will be thrown by the FileInputStream, FileOutputStream, and RandomAccessFile constructors.


If the given class name is not existing at the time of compilation or running of program then ClassNotFoundException will be raised. In other words this exception is occured when an application tries to load a class but no definition for the specified class name could be found.


This is exception is raised whenever problem occurred while writing and reading the data in the file. This exception is occurred due to following reason;

  • When try to transfer more data but less data are present.
  • When try to read data which is corrupted.
  • When try to write on file but file is read only.


This exception is raised whenever one thread is disturb the other thread. In other words this exception is thrown when a thread is waiting, sleeping, or otherwise occupied, and the thread is interrupted, either before or during the activity.


This exception is raised because of problem in arithmetic operation like divide by zero. In other words this exception is thrown when an exceptional arithmetic condition has occurred. For example, an integer "divide by zero".


class ExceptionDemo 
public static void main(String[] args) 
int a=10, ans=0;
catch (Exception e)
System.out.println("Denominator not be zero");


This exception will be raised whenever given index value of an array is out of range. The index is either negative or greater than or equal to the size of the array.


int a[]=new int[5];  
a[10]=100; //ArrayIndexOutOfBoundsException 


This exception will be raised whenever given index value of string is out of range. The index is either negative or greater than or equal to the size of the array.


String s="Hello"; 
s.charAt(10); // Exception raised

chatAt() is a predefined method of string class used to get the individual characters based on index value.


This exception will be raised whenever you trying to store any input value in the un-authorized datatype.

Example: Storing string value into int datatype.


int a;


String s="hello";  
int i=Integer.parseInt(s);//NumberFormatException  


This exception will be raised whenever calling method is not existing in the program.


A NullPointerException is thrown when an application is trying to use or access an object whose reference equals to null.


String s=null;


This exception throw when full the stack because the recursion method are stored in stack area.

Prev Tutorial Next Tutorial


Buy This Ad Space @$20 per Month, Ad Size 600X200 Contact on: hitesh.xc@gmail.com or 8076671483

Pure VPN Privide Lowest Price VPN Just @ $1.65. Per Month with Non Detected IP Lowest Price Non Detected IP VPN

Magenet is best Adsense Alternative here we earn $2 for single link, Here we get links ads. Magenet

Download Projects

Google Advertisements

Buy Websites 9999595223

Buy Fresh and Payment Receive Media.net Account with Website. Contact on: hitesh.xc@gmail.com or 9999595223 Try this Keyword C++ Programs