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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T20:17:03+00:00 2026-06-12T20:17:03+00:00

I am looking for suggestion on how to handle exception in java in a

  • 0

I am looking for suggestion on how to handle exception in java in a scenario, where

Class A.test() 
{
    ClassB.test1()
}


test1()
{
   Map listOfExceptions = new HashMap();
   for()
   {
      try{
      }
      catch(custException e){
       // I want the for loop to continue even if there is an exception
       //So I am not throughing now rather adding the exception message to map with 
       //the field name for which for loop is running as key and message as value
      {
   }

// at some point if map has >0 records I want to throw an exception to classA.
}

So the question here is how can I add the Map data to the exception thrown ? basically I need the list of exceptions to be sent to the calling method, as part of exception handling.
Is there a way we can do this ?
It might be a very silly question if the answer is wellknown but I dint find the exact answer anywhere.

  • 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-12T20:17:04+00:00Added an answer on June 12, 2026 at 8:17 pm

    Why not just build a List<Exception> as you iterate ? Then upon completion throw a CustomException (derived from Exception) if that list is not empty, and provide the List<Exception> as a field in that CustomException.

    You may prefer not to store a List<Exception> but a List<Info> where Info represents the data resulting in the exception. That would likely be more lightweight.

    Better still, create an ErrorCollator object that you can add Exceptions to as they occur. Once you’re done, call ErrorCollator.throwExceptionIfReqd(), and that object itself can determine whether to throw the exception (simply, if the List is not empty). That way you have a reusable component/pattern that you can use consistently. Perhaps worth working towards, if not doing immediately.

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

Sidebar

Related Questions

We are starting a new Java EE project and am looking for suggestions regarding
I was looking for any suggestion or a good approach to handle messages between
I'm looking for a best practice suggestion. I've got a ShoppingBag Controller with a
I'm looking for something similar to facebook suggestion list with cities and countries. You
i am new to android programming.i looking to make a question and answer application.in
I'm looking to develop a good shopping cart to my new store site. I
Hi I'm looking for suggestions on how best to handle the submission of a
I'm looking to handle image uploads on a site I'm building. All the behind
I am looking into different ways to handle updating an ASP.NET application across many
I am looking to build a web site/application. The class model is around 100

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.