No, but that would have been easy enough to test. The following does compile:

Is there a question here you are looking for an answer to?

Sandya Bhaskara
Ranch Hand

Joined: Aug 20, 2004
Posts: 73

posted Aug 27, 2004 17:26:00

0

here...meth()doesn't throw any checked exceptions..and method() is catching the only runtime exception that meth() throws..so why doesn't the compiler give an error?- catching an exception(here---catch (Exception e)) that has never been thrown??any exception that isnt a checked exception is a runtime exception...and that is caught by the code..so is it ok to catch Exception again??am i clear?

It doesn't seem to violate any of the exception rules. You must declare that a method "throws" exception or provide a catch clause for it only if it is checked exception. RuntimeException and its subclasses are considered unchecked.

Chris Allen
Ranch Hand

Joined: Feb 01, 2003
Posts: 127

posted Aug 28, 2004 06:49:00

0

It won't compile without adding a semicolon the following line: throw new RuntimeException()