aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Constructor Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Constructor" Watch "Constructor" New topic
Author

Constructor

Thiru Thangavelu
Ranch Hand

Joined: Aug 29, 2001
Posts: 219
There is no exception thrown in class A. How is it possible to instantiate the class A inside the try.. catch. I expected a error, "there is no exception thrown in class A". Can anyone clarify this?

[ June 19, 2002: Message edited by: Thiru Thangavelu ]

Thanks,<br />Thiru<br />[SCJP,SCWCD,SCBCD]
Corey McGlone
Ranch Hand

Joined: Dec 20, 2001
Posts: 3271
Notice that your catch block catches "Exceptions". It doesn't catch IOException. One of the descendents of Exception is RuntimeException. As RuntimeExceptions need not be declared, you are free to try to catch them at any time. If you change that catch block to catch an IOException, I'll bet you'll get the compiler error you expected.
Corey
[ June 19, 2002: Message edited by: Corey McGlone ]

SCJP Tipline, etc.
Thiru Thangavelu
Ranch Hand

Joined: Aug 29, 2001
Posts: 219
Even this compiles fine how?
Thiru Thangavelu
Ranch Hand

Joined: Aug 29, 2001
Posts: 219
Thanks as always Corey,
that cleared my doubt.
Jose Botella
Ranch Hand

Joined: Jul 03, 2001
Posts: 2120
Exception is the only checked exception that can be declared within a catch clause without being thrown.


SCJP2. Please Indent your code using UBB Code
Thiru Thangavelu
Ranch Hand

Joined: Aug 29, 2001
Posts: 219
how about Throwable?
Corey McGlone
Ranch Hand

Joined: Dec 20, 2001
Posts: 3271
Originally posted by Thiru Thangavelu:
how about Throwable?

Only descendents of Exception (with the exclusion of RuntimeException) are considered checked exceptions. Anything else (RuntimeException and anything higher on the inheritance hierarchy) is not checked.
Corey
Paul Villangca
Ranch Hand

Joined: Jun 04, 2002
Posts: 133
Besides, Error is a subclass of java.lang.Throwable, and we're not required to check for errors, only checked exceptions.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Constructor