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 9173435
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T16:35:22+00:00 2026-06-17T16:35:22+00:00

First, here is my code : public static boolean loginValide(final String username, final String

  • 0

First, here is my code :

public static boolean loginValide(final String username, final String password) throws IOException {
    final boolean valide = false;
    final String postData = "somePostParameters";
    URL url;
    HttpsURLConnection connexion;

    url = new URL("someUrl");
    connexion = (HttpsURLConnection) url.openConnection();
    try {
        connexion.setDoOutput(true);

        final DataOutputStream dos = new DataOutputStream(connexion.getOutputStream());
        dos.writeBytes(postData);
        dos.flush();
        dos.close();

        final int responseCode = connexion.getResponseCode();
        if (responseCode == HttpURLConnection.HTTP_ACCEPTED) {
            // ...
        }
        else {
            // ...
        }
    } catch (final IOException e) {
        throw new IOException(e); /* I am retrowing an exception so the
        finally block is still called */
    }
    finally {
        connexion.disconnect(); // Close the connection
    }

    return valide;
}

My problem is that I was first only declaring my method throwing an IOException. But if it happens, I suppose the HttpsUrlConnection would not be disconnected.
So I thought catching the Exception, rethrowing it so when my method is called by another class I can handle a network/connection error and tell the user about it, and so the code will still run the finally block to close the connection.

First, am I right? Or is there another way to do this?
I don’t care about the try{} catch{} inside the method, I just want to be sure that the connection and streams will always be closed, whether an exception is thrown or not.

The other problem is the catch{} block where I throw the exception. Eclipse tells me:

Call requires API level 9 (current min is 8): new java.io.IOException

Seriously, I can’t throw an exception using an API level below 9? I hope it’s a joke…

  • 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-06-17T16:35:23+00:00Added an answer on June 17, 2026 at 4:35 pm

    Code in a finally block will always be called, even if the code in the try-block throws an exception. As for the API level restriction – it’s the specific IOException(Throwable) constructor that was added in API level 9.

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

Sidebar

Related Questions

First off here is the code! <!DOCTYPE html PUBLIC -//W3C//DTD XHTML 1.0 Strict//EN http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd>
Here is the first part of my controller code: public class ControlMController : Controller
Here's sample model classes, which being use with Entity Framework Code First: public class
First, here is the C# code and the disassembled IL: public class Program<T> {
Here is the code: string str; cin>>str; cout<<first input:<<str<<endl; getline(cin, str); cout<<line input:<<str<<endl; The
So, first off here's my code to open the dotx and create a new
first post here, and probably an easy one. I've got the code from Processing's
my first question here! I have a problem with a piece of code that
i have two dropdown list. first drop down:1 enter code here <form:select path=custName id=custName>
Let me first put the code snippets here. I am just using the ASP.NET

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.