A question regarding Exceptions. Please SEE

Hi there,

I have a Question regarding 'Exceptions'.

If the code written,generates an ArithmeticException,

what exactly happens?

int x=20;

try{

x/0;

}catch(ArithmeticException aE){

}

ArithmeticException extends RuntimeException which extends Exception

which extends Throwable which extends Object.

So,the hierarchy is:

Object

Throwable

Exception

RuntimeException

ArithmeticException

Now,when the ArithmeticException is thrown in the above code,this class

calls its superclass passing the name of the exception in its constructor?

ie,ArithmeticException constructor will be

super("Arithmetic Exception");

Am I right till this point?

This goes on going upwards till Throwable is reached? ie each class's constructor

calls its superclass's constructor.

Am I right till this second point?

What HAPPENS which Throwable is reached?

Does Throwable's constructor call the Object's constructor?

[1325 byte] By [bhuru_luthria] at [2007-9-30 18:56:12]
# 1

From the API: ArithmeticException(String s): Constructs an ArithmeticException with the specified detail message. The argument is a message, not the name of the exception (in this case, the message will likely be something like "Division by zero").

What ArithmeticException does in it's constructor is unknown. It will call some constructor from its superclass, that's for sure (if it doesn't explicitly say which one, the no-argument constructor will be called automatically).

That's also the answer to your last question: Object only has a no-argument constructor, so that's the one that will get called.

BTW, this is not really unique to Exceptions. The same thing applies to any object in an inheritance hierarchy.

Herko_ter_Horst at 2007-7-6 21:14:51 > top of Java-index,Java Essentials,Java Programming...