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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T20:01:27+00:00 2026-06-08T20:01:27+00:00

Description: I am always told by people check all your parameters all the time

  • 0

Description:
I am always told by people check all your parameters all the time which results in a lot of if checks and try catches.

Question:
In the code below I cleaned the code such that only method that handles the exception handling is at the root method that is exposed publicly and not in the refactored private helper methods. Is this practice ok?

I’m not handling exceptions closer to the methods they could occur in but the code is much cleaner.

Code Notes:

  • Method validateInputs() not included.
  • ParameterObject a is derived let say from parameters created through “someCode”, it represents parameters I want to pass around. Anytime I have a need for more than 2 parameters i refactor those parameters to a parameter object.

Code:

public class UnderTest {

    public UnderTest() {}

    public boolean runWork(  String someValue ) throws CustomException
    {
        try
        {
            validateInputs();
            // someCode
            .
            .
            processWork(  ParameterObject a );
        }
        catch( Exception e )
        {
            logError(e);
        }
    }

    private void processWork( ParameterObject a  )
    {
        Operation1( ParameterObject a  );
        Operation2( ParameterObject a  );
    }

    private void Operation1( ParameterObject a  )
    {
        // someCode
    }

    private void Operation2( ParameterObject a  )
    {
        // someCode
    }

    private void logError(Exception e)
    {    
        throw new CustomException(e,"Message");
    }        
}
  • 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-08T20:01:31+00:00Added an answer on June 8, 2026 at 8:01 pm

    I tend to check arguments when they enter the class by some public API. In private methods I check only by assertions or not at all. This implies that I trust my own class a bit more.

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

Sidebar

Related Questions

Short problem description: XCode 4.2 install right Target on device, but debug (run) always
Hi Stackoverflow people, In the past, I always developed my Django projects locally with
I'm always confused as to which way is the best to do the following.
In spring you always use the web.config / app.config for storing your objects like
Using the WPF Grid control is easy when your child elements are always contained
BranchState is a class which has the following properties: State Branch AgencyId Description With
I have alot of not always static values (slogan, banner, description...) and PartialViews (block_head,
The results for the ruby-prof output always contains a value for the Wait column.
Thanks ahead of time for the help Description: The program draws, displays, and saves
I always notice people have different reactions to different ways of creating a timer

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.