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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T01:05:35+00:00 2026-06-02T01:05:35+00:00

I am new to Java language and cannot understand the behavior of finally block

  • 0

I am new to Java language and cannot understand the behavior of finally block in this program. This program should exit after printing BC whereas it is printing BCD. Please help.

class Main 
{  
    public static void main(String [] args) 
    {
        try 
        {
            badMethod();  
            System.out.print("A"); 
        }  
        catch (Exception ex) 
        {
            System.out.print("B");  
        } 
        finally 
        {
            System.out.print("C"); 
        } 
        System.out.print("D"); 
    }  
    public static void badMethod() throws Exception
    {
        throw new Exception(); /* Line 22 */
    } 
}
  • 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-02T01:05:37+00:00Added an answer on June 2, 2026 at 1:05 am

    You’re catching the exception (in the catch block) and not rethrowing it – so you’re effectively handling the exception, and execution then proceeds as if it weren’t thrown. The program only exits because it reaches the end of the main method – it’s not like it’s terminated abruptly.

    If you change your code to either rethrow the exception from the catch block or just don’t catch it in the first place (both of which will require you to declare that main throws Exception, of course) then it won’t print D.

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

Sidebar

Related Questions

I'm very new to Java programming language so this is probably dumb question but
This question is for the java language in particular. I understand that there is
Eclipse and MyEclipse create new Java files with an extra blank line after the
I'm very new to developing on Android and the Java language in general and
According to the Java Language Specification , constructors cannot be marked synchronized because other
<%@ page language=java import=net.sf.json.JSONArray %> <% JSONArray arrayObj=new JSONArray(); arrayObj.add(MCA); arrayObj.add(Amit Kumar); arrayObj.add(19-12-1986); arrayObj.add(24);
Im very new to acceleo , for text generation(for java language) i'm using ecore
Hello fellow stackoverflow members! I'm very new to the C# language transfer from Java,
I'm using VB.NET but this question applies to any OO language - Java, C#
I am very new to symfony. In other languages like java and others 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.