File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Performance and the fly likes A doubt in exception handling Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Performance
Bookmark "A doubt in exception handling" Watch "A doubt in exception handling" New topic
Author

A doubt in exception handling

rajaraman navaneethan
Ranch Hand

Joined: Feb 26, 2005
Posts: 86
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

Joined: Jul 11, 2001
Posts: 14112
Not a performance question - moving to Java in General (beginner)...


The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: A doubt in exception handling