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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T09:29:22+00:00 2026-06-09T09:29:22+00:00

Hey StackOverflow Community, Regarding throwing exceptions. Generally, when do I throw and exception, and

  • 0

Hey StackOverflow Community,

Regarding throwing exceptions. Generally, when do I throw and exception, and when do I catch it?

Let’ say I come across these situation where I have to quit because of some problem that occurred and I can’t recover from it. Do I throw or do I catch?

I do this right now:

    try {
       // some code
    }
    catch (IOException e) {
       logger.info("Failed to do something, and cannot continue" + e.getMessage(), e);
       e.printStackTrace();
       throw e;
    }

Is this the right thing to do? Would it be more appropriate if I just threw the exception? Sorry, I’m a newbie at exceptions 🙂

  • 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-09T09:29:24+00:00Added an answer on June 9, 2026 at 9:29 am

    You generally catch an exception in a method when you want your program to continue running. You throw an exception when you want a higher level method that is calling that method to handle the exception instead. For example, you might throw it all the way back to your Main method, which has a try..catch block (likely with different catch blocks for different exceptions) encapsulating all your method calls, and exceptions can be handled there (for example by ending the program).

    Remember that throwing an exception will end the method immediately. This affects the flow of your code. If you might have an exception in the middle of the method, and the code below it can’t run if that exception happened, then you would need to either wrap the whole section in a try/catch block or throw an exception.

    A general word of advice – printStackTrace() is bad. You can create better error output yourself (and you can include the stack trace as well with your output). Even better, use logging.

    I recommend reading this introduction to exceptions and this article which covers good and bad exception patterns.

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

Sidebar

Related Questions

Hey StackOverflow community, My question is as follows: I have a table, say USER_ADDR
Hello StackOverflow Community, <plist> <dict> <key>Non Random Key</key> <dict> <key>Random Key</key> <dict> <key>Hello</key> <string>Hey</string>
Hey Guys, I usually come to StackOverflow for my php coding answers, although this
Hey stackoverflow community! I'm having an issue where a highly involved algorithmic program is
Hey StackOverflow Community, So, I have this line of information from a txt file
Hey Stackoverflow I'm working on my homework and I'm trying to reverse a circular-linked
Hey, I've been reading StackOverflow.com for a long time but decided to sign up
I'm playing around with Interops and I thought: Hey let's code something that accesses
hey guys how to make these php html links codes possible. i have tried
Hey stackoverflow - This is my first question here. I have 2 tables in

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.