File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Exceptions Handling in Constructors 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 "Exceptions Handling in Constructors" Watch "Exceptions Handling in Constructors" New topic

Exceptions Handling in Constructors

Kaushik Subramanya

Joined: Sep 26, 2000
Posts: 9
Can anyone tell me how do I catch and handle exceptions within my constructor.
Paul Anilprem
Enthuware Software Support
Ranch Hand

Joined: Sep 23, 2000
Posts: 3635
It's exactly same as the way you throw/catch exceptions in any method.
Get Certified, Guaranteed!
(Now Revised for the new Pattern)

Enthuware - Best Mock Exams and Questions for Oracle Java Certifications
Quality Guaranteed - Pass or Full Refund!
William Brogden
Author and all-around good cowpoke

Joined: Mar 22, 2000
Posts: 13036
However, unless the exception is something that you can recover from and still produce a valid object, it is better to let the constructor throw the exception and handle the problem somewhere else.

author of:
I agree. Here's the link:
subject: Exceptions Handling in Constructors
It's not a secret anymore!