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

  • Home
  • SEARCH
  • 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 1051871
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T17:00:16+00:00 2026-05-16T17:00:16+00:00

I have question about try, catch and finally in Java. Consider the following scenario:

  • 0

I have question about try, catch and finally in Java. Consider the following scenario:

try{
//Some code here that throws IOExceotion
} 
catch (IOException ex){
System.out.println("Line 1: IOException Encountered!");
throw ex;
}
finally {
System.out.println("Line 2: I am always executed!");
}

What would be the output of the code snippet above?
Am I going to see:

Line 1: IOException Encountered!
Line 2: I am always executed!

or would it be

Line 2: I am always executed!
Line 1: IOException Encountered!

Or would it be just (since we have a throw in the catch block)

Line 1: IOException Encountered!

Basically, I haven’t found an example where there is a “throw” in the catch block and finally block following the catch block (like the example above). Can anyone shed some light on it?

Thanks.

  • 1 1 Answer
  • 2 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-16T17:00:17+00:00Added an answer on May 16, 2026 at 5:00 pm

    You will see the first one. Finally block is executed always and as a last.

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

Sidebar

Related Questions

I have a question about how GC works in Java. Consider the following code:
Consider the following code: try { int *i = NULL; i[100] = 20; catch
I have several questions about best use of exceptions in Java. Consider the code
I have question about throw. How will the throw work in the following code?
I have a very simple question about re-throwing exception in Java. Here is the
everyone. I have a rookie question about the returning value in java. Here's my
I know of cours that here were some question about this, but I still
I have a question about SqlDataReader: Is there some way to modificated the values
I have a question about arithmetic behaviour in R. Regard the following piece of
I have a question about loading an image from a website. The code I

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.