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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T01:41:45+00:00 2026-05-26T01:41:45+00:00

It’s a really stupid question but I was wondering something. I have a variable

  • 0

It’s a really stupid question but I was wondering something. I have a variable that I have to fill up with an Integer. In some case the source from where I’m getting the data could return an empty string or just be offline.
I do not have to handle the offline case because the program will never come this far if the source it’s offline. So I thought to do something like this:

    int i = 0;
    try {
        i = mySource.getInt();
    }
    finally {
        System.out.println(i);
    }

int i = 0 is my base value so if I have to parse the empty string I’ll just use the initial value. In this case we’re gonna generate an exception and it will not be catched. Is there a way to do something like this without handling the exception (so without using catch(Exception e){}) or is it just bad practice?

Just to clarify: I do not need to check if the source is online now because it’s a parsed xml file so I’ll check if it’s offline when I’m downloading the file.

  • 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-26T01:41:45+00:00Added an answer on May 26, 2026 at 1:41 am

    The exception will propagate if you don’t catch it. Since you know what caused the exception, you don’t want control flow to be interrupted, and you just want the default value, propagating the exception doesn’t do any good. Just catch it and eat it, then use the default value.

    The time to use try ... finally with no catch is when you have something that needs cleaning up (a resource that needs closing, usually), but you don’t want to handle any exceptions that might get thrown, you want to let them go. This is the opposite case, you don’t have anything that needs closing, you just want to squelch the exception and use a default value.

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

Sidebar

Related Questions

I have a French site that I want to parse, but am running into
I have just tried to save a simple *.rtf file with some websites and
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have some data like this: 1 2 3 4 5 9 2 6
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a jquery bug and I've been looking for hours now, I can't

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.