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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T00:14:41+00:00 2026-05-28T00:14:41+00:00

I have a try – catch block that I wish to break like a

  • 0

I have a try–catch block that I wish to break like a switch block but I couldn’t find a recommended way of doing it. I’m fetching a lot of data in the try–catch block and wish to stop the fetching in between in case a certain condition is met. Just to get it working for now, I’ve deliberately forced the code to go into the catch block:

int i=0;
    try {
        //--do stuff----
        if(//-------is condition met?--------//)
            i = 1/0; // divide 1 by 0 -- a definite exception
    }
    catch (Exception e) {//---------do nothing---------//}

Is it safe to do this or should I go for another way?

EDIT:I’m fetching some xml data(actually, a lot). Depending on the internet connection, I need to stop the parsing after sometime(time-out) rather than go through the entire stream. I go through loops but I also make some calculations later. It doesn’t make any sense to calculate with incomplete data, so I would prefer to just skip the whole thing.

  • 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-28T00:14:41+00:00Added an answer on May 28, 2026 at 12:14 am

    Either break or throw will do what you want (and the throw would be preferable, you at least have some traceability as to WTH you’re doing.

    [edit]

    what: try {
             System.out.println ("before break");
             break what;
    
          } catch (Exception e) {}
       }
    

    [/edit]

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

Sidebar

Related Questions

i have try some command like system(reboot) exec(reboot) and system(/ect/init.d/networking restart); but not happen
I have wanted to try GAE since launch, but coming from ASP .NET and
We have following code: try { // some code throwing MyException } catch (MyException
I have this code try { //AN EXCEPTION IS GENERATED HERE!!! } catch {
Let's say in one method I have try { callme(); } catch { //
I have try to access the map in jsf using C:foreach.But i can't access
i have try{ ..code.. }catch(err){ err.### what methods do i have access to here
Say I have: try { externalLibrary::doSomething(); } catch (std::exception &e) { //yay I know
i have try TBXML in iOS 5.. but as you know, autorelease is not
I have try to write data to csv using the php function. But the

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.