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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T16:16:25+00:00 2026-06-06T16:16:25+00:00

Suppose there is a situation like : statement 1; statement 2; statement 3; statement

  • 0

Suppose there is a situation like :

statement 1;
statement 2;
statement 3;
statement 4;
statement 5;
statement 6;
statement 7;
statement 8;
statement 9;
statement 10;

Any of these statements is suspected to raise an Exception. So I put them in a try-catch block.

try{
    statement 1;
    statement 2;
    statement 3;
    statement 4;
    statement 5;
    statement 6;
    statement 7;
    statement 8;
    statement 9;
    statement 10;
}catch(Exception e){
    e.printStackTrace();
}

Now, suppose to complete my calculations, I need to process all those 10 statements, no matter what. How do I handle the situation?

For example, say I have 10 Strings. Any of them could throw a NullPointerException when the user decides to leave the field blank(say cases like Not Applicable on forms). If I were to develop the whole project, I could first check of the null and return values accordingly for processing. But assuming I only have to develop this module to process the data.

I could put individual if checks to check which String is null, ignore it’s value in the processing, and move on. But if I have n number of Strings, introducing n if statements wouldn’t be tidy. Would it?

I could have individual try catch and keep processing even if an Exception occurs. But then again, wouldn’t be tidy.

I could analyze the stack trace and get the line number and jump to the next line and resume the processing.(Can I? I’m not sure about it. Jumping back from a catch to a try? Not possible I believe, but still wrote this down as a possibility).

But these methods don’t seem appropriate and correct.

Is there a better and a simpler way to handle such situations? I have just taken example of a String,the data to be processed could be anything, and could generate any Exception.

To repeat my question once again : Is there a way to complete the evaluation of a method or a process, no matter how many exceptions are generated in it?

The question might be a duplicate(I didn’t find one though), or might not be appropriately phrased. Feel free to edit it(or suggest an edit),but keeping the main idea still focused.

  • 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-06T16:16:27+00:00Added an answer on June 6, 2026 at 4:16 pm

    I could put individual if checks to check which String is null, ignore it’s value in the processing, and move on. But if I have n number of Strings, introducing n if statements wouldn’t be tidy. Would it?

    Are you doing the same thing with each string, you should extract the “check and optionally do something” behaviour into a method.

    You definitely shouldn’t call a method on a null reference which you know can legitimately null. NullPointerException should always indicate a bug somewhere (either you shouldn’t have been given the null reference, or if that’s legitimate you should check it before you do anything with it).

    If your method is doing 10 separate things, each of which can fail, it may well be too big to start with. It sounds like they’re independent operations (otherwise you couldn’t perform operation 2 after operation 1 had failed) so put each into a separate method with a try/catch block, and call them from your top-level method.

    Fundamentally this feels like a code smell though – it’s very rarely a good idea to continue blithely with a series of steps in the face of an exception, and almost certainly not just by catching Exception. You should think carefully about whether this is really the design you want.

    There’s definitely nothing in the language to make this easier for you – precisely because it’s almost always the wrong thing to do.

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

Sidebar

Related Questions

Suppose there is a SQL statement: select * from A order by cola In
Just a quick question. I suppose I could just try it but I like
Suppose there are objects making subscriptions to a socket server like so: socket.on('news', obj.socketEvent)
So the situation is like this. Suppose we have: class Test(datetime): def a(self): return
Suppose there is a script sth.py When i logged with 'root' account. type :
Suppose there are two lists a = {a1, a2, a3} and b = {b1,
Suppose there is an image_url column in database. I want the user to choose
Suppose there are ~10,000's of keys, where each key corresponds to a stream of
Suppose there is a table A which has a column AccessRights which is multivalued(
Suppose there is a System A which gives some output. This output is used

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.