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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T12:11:25+00:00 2026-06-13T12:11:25+00:00

I am puzzled by the following design of the method: Map<String, BigDecimal> foo(Parameter p){

  • 0

I am puzzled by the following design of the method:

Map<String, BigDecimal> foo(Parameter p){ ... }

This method takes a complex Parameter and returns a map name -> value. In many cases, based on certain underlying calues of the parameter, the resulting map will be the same, furthermore, there are only a few different maps that can ever be returned, so these will be cached. However, when the map is initially created, there can potentially be different types of errors – certain String value might be incorrect, certain value might be < 0 and therefore should be skipped etc. These errors might be of different nature then. I would like to return this map, but also be able to flag these errros, ideally only once, when the initialization of each map is performed. What would be the cleanest way to do this?

  • 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-13T12:11:26+00:00Added an answer on June 13, 2026 at 12:11 pm

    This is a fairly unusual requirement – if you can generate a valid result in spite of the internal errors, you should probably return that result; and if not, throw the exception.

    But if you do want to return this additional information, then I see you have broadly two options available:

    1. Object-oriented, mutable state. When you’re running foo(), accumulate any internal errors in some field. Expose an additional getFooErrors() method to allow callers to inspect what happened. And possibly a getFooErrorSeverity() method if you need to tell callers the degree to which these errors impacted on the quality of your result map.
    2. Immutable/functional. Return the information from above (exceptions and maybe a severity score) as part of your method. Instead of returning a Map<String, BigDecimal>, return an object which contains the map, as well as the exception details. E.g:

      public class FooResult {
          public final Map<String, BigDecimal> result;
          public final List<Throwable> errors;
          public final int errorSeverity;
      
          // Constructor elided
      }
      

    The first approach is similar to how java.io.PrintWriter works in the standard library. It swallows any IOExceptions encountered by its I/O methods, and exposes a checkError() method to allow callers to see if the writer encountered any exceptions.

    I prefer the second because it doesn’t impact thread-safety, it gives the client all the information up-front, and it’s neatly coupled with the scope where the error was encountered.

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

Sidebar

Related Questions

I am puzzled at the following difference. $str=\xd6\xd0; decode(GBK,$str); vs. $str=d6d0; @list=map \\x.$_,unpack((a2)*, $str);
I am a beginner in js, and am puzzled by the following code: Foo
I'm puzzled over the following code: Proc.new do |a| a.something test puts a.something puts
I am learning some COM code and the following code puzzled me. STDMETHODIMP _(ULONG)
I'm puzzled about the execution order of the following: $('#home').live('pageinit',function(){ $('#test').hide(); $(function() { alert('test1');
I'm a bit puzzled about the conditional operator. Consider the following two lines: Float
I am puzzled why this return false doesn't cancel the post-back. function validate() {
I am really puzzled by this. I believe I am managing memory the correct
okay...im really puzzled with this. I want to create a regular asp.net webforms website
I'm puzzled by the following difference in behaviour: // suppose myfile.txt contains a single

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.