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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T01:28:44+00:00 2026-05-25T01:28:44+00:00

I am very new to exception handling in java, hence this question might seems

  • 0

I am very new to exception handling in java, hence this question might seems stupid but please let it be answered. Suppose i have a method A in which some part of code can throw an exception B then what is the difference between catching the exception in the method or writting the method declaration as:-

void A() throws B{
     ----//----
     }
  • 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-25T01:28:45+00:00Added an answer on May 25, 2026 at 1:28 am

    The difference lies in the way you call the method.

    1. If your method signature says throws Exception, the code that calls your method must deal with the Exception either by catching it [via a catch clause] or throw it back [via throws clause].

    2. If you catch the Exception, you are basically trying to handle the Exception yourself and the code that calls your method does not have to deal with the Exception.

    My advice is as follows:

    1. If you think you can handle and recover from the Exception, that you should catch and do the needful.

    2. If you cannot deal with the Exception properly that do not catch it, you must throw it back.

    NOTE: It is a bad programming style to catch an Exception and re-throw it back [although you can do it]. If you wrap the Exception with another one, then it is ok. But in this case it must make sense to wrap the Exception with another one.

    Update: The idea is, no matter what number of layers your application has, somebody has to deal with that throws Exception clause. You cannot just let a StackTrace appear to the user in the middle of his activity with the application. The point to consider is “Can you recover from the error and resume your processing?” If yes, then handle the Exception, else throw it back to the layer that can at least show a meaningful message to the user about what happened.

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

Sidebar

Related Questions

Warning - I am very new to NHibernate. I know this question seems simple
Very new to FluentNHibernate, but I'm also excited about the area. I've recently started
Im very new to SQL but need to write a query to do the
I am very new to the entity framework, so please bear with me... How
I had very errorsome Exception handling with if-clauses. An exception occurs if not found
I am very very new to clojure. The zip utility looks interesting but I
very new to crystal reports.. Question is that - In our .net application we
Im very new to Hibernate so this will probably a easy task for you
I am very new at java and my be missing something very basic. When
I realize there are a few questions on best practices for exception handling, but

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.