Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6880207
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T04:56:42+00:00 2026-05-27T04:56:42+00:00

I have been very clear that instance initializer cannot throw exception because it is

  • 0

I have been very clear that instance initializer cannot throw exception because it is part of object initialization and developer has no control over this process. This post has the same idea.

However, I have read an article by Bill Venners about the object initialization in java, and there is one paragraph quoted as below:

The code inside an instance initializer may not return. Except in the case of anonymous inner classes, an instance initializer may throw checked exceptions only if the checked exceptions are explicitly declared in the throws clause of every constructor in the class. Instance initializers in anonymous inner classes, on the other hand, can throw any exception.
Please click here for original post.

It seems to say that an instance initializer can throw exception. Could anyone here explain this to me or correct me if my understanding is not correct.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T04:56:43+00:00Added an answer on May 27, 2026 at 4:56 am

    Instance initializers can throw checked exceptions, but if they do, the class constructor has to declare them. For example, this code is legal:

    import java.io.*;
    
    public class MyClass {
    
        PrintStream stream;
    
        {
            stream = new PrintStream("/tmp/file.txt");
        }
    
        public MyClass() throws FileNotFoundException {
        }
    
    }
    

    If, however, the throws clause was omitted from the constructor, or if another constructor was added that didn’t also have the clause this would not compile, because the PrintStream constructor throws FileNotFoundException.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been trying very hard to achieve rounded corners with IE6+jquery ui tabs.
I have been noticing some very strange usage of O(1) in discussion of algorithms
I have been using Hibernate very successfully, but today I noticed a bizarre phenomenon
I have always been a very big fan of the DHTML calendar http://www.dynarch.com/projects/calendar/ I
I have been using SQL Compare by Redgate at my company and was very
I have a very large program which I have been compiling under visual studio
I have just started C very recently and I have been asked to answer
I have been experimenting with Lambda expressions in Oxygene. Very simple recursive lambda expression
I'm very much new to programming and have been doing fairly well so far.
Hi I'm very new to sql but have been passed a job in which

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.