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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T16:23:08+00:00 2026-06-11T16:23:08+00:00

I am building my first Java library. The code uses lots of IO methods,

  • 0

I am building my first Java library. The code uses lots of IO methods, so as you can imagine there are lots of exceptions to be caught. But I’m wondering, should I throw the exceptions? I mean surely it’s the application writer’s job to catch the exceptions. Because even if I catch them, I don’t really know what the application would like to do in the event of this occurrence.

Should I throw IOExceptions etc, or should I catch them in the library code?

  • 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-11T16:23:09+00:00Added an answer on June 11, 2026 at 4:23 pm

    You should handle exceptions only if you can – i.e. if your library has sufficient knowledge on how the exception should be dealt with.

    Here’s an example when you should handle an exception:

    • Library receives request from user
    • Library tries to read a configuration file
    • There is a IOException because the config file is not found
    • Library catches the exception and falls back to using a default configuration (perhaps issuing a warning to the user that there is no configuration file)

    Here’s an example where you should not handle an exception

    • Library receives a request from the user
    • The processing request fails when trying to parse an integer from a String in the request (gets a NumberFormatException)
    • Library cannot handle the exception – assuming a default value (e.g. 0) would be dangerous
    • Exception is thrown back to the user for them to handle

    If you are going to throw an exception to the user, it is often good practice to catch and re-throw the exception – this enables you to wrap it in your own custom exception class and potentially add extra messages / details etc.

    In general remember that if you want to write a good software component then it should have fail-fast behaviour. If in doubt, you should fail and let the user know (via an exception) rather than attempt to continue on an unsound basis.

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

Sidebar

Related Questions

I'm building a text classifier in java with Weka library. First i remove stopwords,
I am building and sort of RSS reader in java as my first object-oriented
I am building a Java Swing gui and I am wondering what the best
I am a java beginner and for my first project I started building a
I'm building a small Java library which has to match units in strings. For
I am building my first Java application using GWT which must read in data
I'm building my first game in Java, from scratch. I've decided that the GameWorld
In my web application (my first with Java, Spring, OR Roo), I'm building a
I'm building a new entity system in Java. I'm wondering whether my proposed method
I'm building a new Java web application for my employer. First thing it needs

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.