Type of exceptions in java are checked exceptions and unchecked exceptions. This classification is based on compile-time checking of exceptions. There is also a classification based on runtime in java. It is not widely known! That is synchronous and asynchronous exceptions. First let us see the java checked exceptions and unchecked exceptions.
Checked Exceptions Vs Unchecked Exceptions in Java
At compile time, the java compiler checks that a program contains handlers for checked exceptions. Java compiler analyzes by which checked exceptions can result from execution of a method or constructor.For each checked exception which is a possible result, the throws clause for the method or constructor must mention the class or its superclasses of that exception.
The class RuntimeException and its subclasses, and the class Error and its subclasses are unchecked exceptions classes. Because the compiler doesn’t forces them to be declared in the throws clause. All the other exception classes that are part of Throwable hierarchy are checked exceptions.
Now let us see a see small discussion on why exceptions are classified as checked exceptions and unchecked exceptions.
Those unchecked exception classes which are the error classes (Error and its subclasses) are exempted from compile-time checking in java because they can occur at many points in the program and recovery from them is difficult or impossible.
Example: OutOfMemoryError
Thrown when the Java Virtual Machine cannot allocate an object because it is out of memory, and no more memory could be made available by the garbage collector.
The runtime exception classes (RuntimeException and its subclasses) are exempted from compile-time checking because, in the judgment of the designers of the Java, having to declare such exceptions would not aid significantly in establishing the correctness of programs.
Example: NullPointerException
Thrown when an application attempts to use null in a case where an object is required.
So the java compiler doesn’t forces them to be declared in the above two cases.
Synchronous and Asynchronous Exceptions in Java
The interpreter executes the java program sequentially. An exception E can occur relative to a line (L) of program. That is that exception E will always occur at the execution of that line L. This is called Synchronous exception.
An asynchronous exception in java can occur at any point in the execution of a program.
They occur only as a result of:
- An invocation of the stop methods of class Thread or ThreadGroup
- An internal error in the Java virtual machine














‘this’ keyword in java programs is used to make a call to the constructor of the same class.
Henna Mullaji on October 19th, 2009 3:16 pmnice explanation..thanks!! keep up the good work.
Goutham on November 10th, 2009 3:46 pmWelcome Goutham
Joe on November 11th, 2009 6:28 pmVery Nice and So much good explanation of the topic.
PR Chauhan on December 4th, 2009 10:25 pmSo much thanks
PR Chauhan
prchauhan@hotmail.com
welll
Anonymous on December 19th, 2009 11:20 pmgood explanantion really helpful
manoj on January 22nd, 2010 8:45 pmhi,
I just want to know one thing in exception handling mechanism. FileNotFound is a checked exception.It means we are handling at compile time.But it is caught at run time when program executes. How a JVM will decide which none is Checked exception and Which one is Unchecked exception.
Can you explain the whole scenario of Exception handling ?
Sandy on June 14th, 2010 12:21 pmThanks
Sandy
Hi joe,
Very nice explonation…
I am very new to java.. can you please suggest me whcih books do i need to refer for java,Servlets and JSPs..
varun on January 13th, 2011 12:21 pmChecked Exceptions are exceptions that are handled by the compliler compile time.But it is caught at run time when program executes. How a JVM will decide which one is Checked exception and Which one is Unchecked exception.
komala on January 21st, 2011 10:38 amyesterday i was asked the same question. But i could not answer it. But really this is a nice explanation. And i got the answer.
Thanx a lot buddy…
Arun Raut on February 5th, 2011 6:16 pmvery nice………
Francis Antony on March 3rd, 2011 8:31 amexcellent explaination i love this site..
vema on April 11th, 2011 10:25 amplz put some sample example
deep on June 27th, 2011 10:24 amchecked exception are those exception which are declare as already it simple mean if we compile our program then it shows a specified exception …..eg.
anand on July 6th, 2011 10:58 pmimport static java.lang.System.*;
import static javax.lang.Timer .*;
using this packade we get the checked exceptipon error .it give CE error
Nice Explanation
sri on July 19th, 2011 11:19 amNice Explanation, Keep Up The Good Work – Thanks !!
Pranjal on October 15th, 2011 12:44 pmnice example
Rajeev on October 15th, 2011 6:59 pmit’s nice. very good. at the same time little bit depth is required
naidu on November 22nd, 2011 9:16 amhow compiler find in comilation time whether that exception is checked or unchecked… can anyone help me about that??
Anonymous on November 24th, 2011 6:52 pmis not a correct explanation.
Anonymous on November 30th, 2011 1:43 pmToday I understood the diff b/w checked, unchecked exceptions.. good article for beginners.
Anonymous on December 17th, 2011 8:39 amExcellent explanation. Keep going on…….
Muruga G on December 18th, 2011 7:26 amnice but some missing
please checked this url
http://tutorials.jenkov.com/java-exception-handling/checked-or-unchecked-exceptions.html
idrish on December 26th, 2011 4:50 amhi joe,
sabjeet rai on January 21st, 2012 8:35 pmi am a java student, i want to know that what
is java native interface(JNI)….
Checked exceptions are actually incredibly convenient. It kills me when I see other programmers catch the superclass and do something generic when they could do something specific to handle the various exceptions they might get.
I also am discouraged by .NET code that has try/catch littered at various parts in a huge block of code that more or less act as continue statements in a foreach.
Java can be a slow and painful beast, but they did at least make it easy to put some love into your exception handling. Much encouraged, and very appreciated to your maintainers when you do!
josh on February 2nd, 2012 2:31 amvery useful………..thanks
by
retheeshmeda on February 2nd, 2012 10:09 amMeda……
I also feel very bad when people use exception handling for flow control.
There is a wrong statement. Java is not slow. If you say so, you might be using jdk1.2 or less. Latest versions compete on par with C with respect to performance.
Joe on February 2nd, 2012 7:32 pmThanks for this information. Nice work.
Anonymous on February 6th, 2012 11:13 pmThank you so much……
shailesh on February 13th, 2012 2:04 pmThanks for knowledge about checked and unchecked exception…….
Pushpendra Singh on February 16th, 2012 6:27 pmThank u very much..
Pushpendra Singh on February 16th, 2012 6:28 pmyes its really a good explanation.
megha on March 16th, 2012 2:05 pm[...] Like NullPointerException, one exception that is very popular is ClassNotFoundException. At least in your beginner stage you might have got umpteen number of ClassNotFoundException. Java class loader is the culprit that is causing this exception. [...]
Java Class Loader&hellip on March 28th, 2012 9:12 amsir i was inot able to understand it can u explain it in a much more simpler way like i have mmy exam on 17th
athul on April 10th, 2012 1:30 pmits really nice notes
varun on April 11th, 2012 10:42 pmI am not happy with the diff given between checked ad unchecked exceptions.You should give some examples abt the same and explain.
shishir on April 18th, 2012 12:07 pmI m a c language & faculty following yr blog cont. to learn java. Please do the needful…
your post are really nice..
one small suggestion have tabular format comparison for differece description. :)
Thanks,
vennila on April 19th, 2012 5:01 pmvennila
sir u need to more describe Synchronous and Asynchronous Exceptions in Java.And Checked Exception.
vipin yadav on April 20th, 2012 2:06 amnice work really its soo nice
Anonymous on April 26th, 2012 5:32 pmGreat work joe keep it up it has helped me a lot my java examination questions
Chitrank on April 27th, 2012 8:01 pmit is too short try make some extra matter in exceptions,present it is useful of me.Thankyou.
vijju on April 27th, 2012 8:47 pmNIce Job and is Very HelpFul to all Of us
Ankur Paliwal on April 30th, 2012 10:09 amHai sir,
How compiler find in compilation time whether that exception is checked or unchecked… can anyone help me about that??
karthik on May 4th, 2012 10:52 amimport java.util.Scanner;
class std{
int mark;
public void get()
{
Scanner a=new Scanner(System.in);
System.out.println(“Enter the Number:”);
mark=a.nextInt();
}
public void set()
{
if(mark=50 && mark<=60)
System.out.println("Pass class");
}
public static void main(String args[])
{
new std().get();
new std().set();
}
}
Explain this program plz the result is not getting perfect
mangesh on May 13th, 2012 9:03 amhi,
how jvm will identify,which is one is checked,unchecked exception.and filenotfound exception is a checked exception but this will happen at run time.please clarify my doubt
Rafi on May 16th, 2012 8:56 pmHi Joe,
Menaka on May 17th, 2012 11:48 amI have a doubt in this…Runtime Exceptions and Erros can’t be caught in compile time so it may fall under Synchronous or Asynchronous exceptions rite???please clarify my doubt..