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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T05:45:38+00:00 2026-06-04T05:45:38+00:00

Option A: public void method() { try { // some operation that throws FirstException

  • 0

Option A:

public void method() {
  try {
    // some operation that throws FirstException
  } catch (FirstException ex) {
    throw new RuntimeException(ex);
  }
  try {
    // some operation that throws SecondException
  } catch (SecondException ex) {
    throw new RuntimeException(ex);
  }
}

Option B:

public void method() {
  try {
    // some operation that throws FirstException
    // some operation that throws SecondException
  } catch (FirstException ex) {
    throw new RuntimeException(ex);
  } catch (SecondException ex) {
    throw new RuntimeException(ex);
  }
}

Which one is better and why?

  • 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-04T05:45:42+00:00Added an answer on June 4, 2026 at 5:45 am

    If your question is about performance then No, there is no difference in both the options. They both have the same processing overhead, the same amount of compilation time (more or less). The question is more about functionality and readability.

    Ofcourse option B is more readable.

    But if you were not throwing a RuntimeException in your catch blocks then i would have suggested using option A because in option A the second operation will execute even if the first exception is thrown.

    After an exception is thrown from a try block the execution control will never return to the same try block.

    But in option A since both operations are in a separate try block, unlike option B, so there will be no such problem. After encountering an exception in first operation and handling it you can continue to second operation if you code permits in option A.

    However if you are adamant about throwing RuntimeException from catch blocks then like i said there is no difference in either option except for readability.

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

Sidebar

Related Questions

I have a Java method that accepts a Long value: (in Java) public void
I want a method that can throw any Throwable including sub classes of Exception.
I got a program that writes some data to a file using a method
Here's the properties and the method that connects. protected Socket _socketConnection = new Socket(AddressFamily.InterNetwork,
Which Doxygen option can completely disable sorting members by type (Private / Public /
I'm using a thread that is continuously reading from a queue. Something like: public
Suppose I have a custom collection class that provides some internal thread synchronization. For
I have a method that I need to run when the activity starts. I've
I have a ViewModel that encapsulates some properties that are being edited in an
I have created the following function: public void DelegatedCall(Action<Object> delegatedMethod) And defined the following

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.