Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

A doubt in exception handling

 
rajaraman navaneethan
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hello friends plz get me cleared of the following doubt in exception handling.

class a
{
public static void main(String args[])
{
int i=6;
try
{
int j;
j=6/0;
}
catch(Exception e)
{
e.printStackTrace();
}
catch(ArithmeticException s)
{
s.printStackTrace();
}
}
}
we know that this code will give an error since the Exception object e catches all types of exceptions,so the second catch becomes unreachable and leads to error.
my question is how does the Exception class being a super class is able to handle the exceptions of its subclasses,such as ArithmeticException and ArrayIndexOutOfBounds?
normally a super class does not have the knowledge of its subclasses.
plz mail the reply.
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not a performance question - moving to Java in General (beginner)...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic